Use encapsulation principal in CivilVehicle
Since every occurrence of collide should set currentAccident and broken for all cars, use setCurrentAccident() for both cars in collide() which sets both values. Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
e65d3d16e9
commit
b70bad851e
@ -1,6 +1,6 @@
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public abstract class CivilVehicle extends Vehicle implements Breakable {
|
public abstract class CivilVehicle extends Vehicle implements Breakable {
|
||||||
|
|
||||||
private boolean broken;
|
private boolean broken;
|
||||||
private Accident currentAccident;
|
private Accident currentAccident;
|
||||||
@ -22,7 +22,7 @@ public abstract class CivilVehicle extends Vehicle implements Breakable {
|
|||||||
cars[0] = this;
|
cars[0] = this;
|
||||||
cars[1] = car;
|
cars[1] = car;
|
||||||
Accident accident = new Accident(time, cars, location);
|
Accident accident = new Accident(time, cars, location);
|
||||||
this.currentAccident = accident;
|
this.setCurrentAccident(accident);
|
||||||
if (car instanceof CivilVehicle)
|
if (car instanceof CivilVehicle)
|
||||||
((CivilVehicle)car).setCurrentAccident(accident);
|
((CivilVehicle)car).setCurrentAccident(accident);
|
||||||
return accident;
|
return accident;
|
||||||
@ -51,6 +51,9 @@ public abstract class CivilVehicle extends Vehicle implements Breakable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentAccident(Accident accident){
|
public void setCurrentAccident(Accident accident){
|
||||||
if (accident != null) this.currentAccident = accident;
|
if (accident != null) {
|
||||||
|
this.currentAccident = accident;
|
||||||
|
this._break(accident.getDate());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user