我有以下课程。
Car{}
TwoWheeler exteends Car{}
FourWheeler extends Car{}
RandomClass{
CarFactory carfactory
//Inject factory using guice
public RandomClass(Carfactory carfactory){
this.carfactory= carfactory;
}
void doSometing(String carType){
carfactory.getCar(CarType)
}
}
CarFactory{
Map<String,Car> carTypeToCarMap;
Car getCarByType(String type){
return carTypeToCarMap.get(type);
}
}
我可以避免基于carType创建工厂并从guice获取实例吗?
答案 0 :(得分:0)
@AutoValue
public abstract class Car {
public abstract Map<String> getCarType();
public static Car.Builder builder() { return new AutoValue_Car.Builder(); }
@AutoValue.Builder
public abstract static class Builder {
public abstract PatientDto.Builder setCarType(String carType);
public abstract Car build();
}
}