我有以下问题。我必须在 makeLeftTurnMethod 内部进行投射......这对我来说看起来很丑陋......有没有办法让我不必这样做?
public interface Car(){
public void turnRight();
public void turnLeft();
public void go();
}
public class LuxuryCare implements Car(){
public void systemCheckRightSideClear();
public void systemCheckLeftSideClear();
}
public class UsedCar implements Car(){
public void personCheckRightSideClear();
public void personCheckLeftSideClear();
}
public interface Run{
public void makeLeftTurn();
}
public class RunLuxuryCar implements Run{
public void makeLeftTurn(Car car){
car = (LuxuryCar)car;
car.systemCheckLeftSideClear();
car.turnLeft();
}
}
public class RunUsedCar implements Run{
public void makeLeftTurn(Car car){
car = (UsedCar)car;
car.personCheckLeftSideClear();
car.turnLeft();
}
}
public void tester(){
//Could return either used or luxuy car
Run run = RunFactory.getInstance(UsedCar);
Car car = CarFacory.getInstance(usedCar);
run.makeLeftTurn(car);
}