I need to implement Builder pattern without static nested classes. What is the best approach for doing it if I have inheritance? Let's imagine I have the following classes.
public class Car {
private String brand;
private String speed;
//getters an setters
}
public class PassengerCar extends Car{
private String capacity;
//getters an setters
}
public class Truck extends Car{
private String length;
//getters an setters
}
Is it better to create one Builder class that will responsible for setting values of PassengerCar and Truck or we need 3 additional classes, CarBuilder, PassengerCarBuilder extends CarBuilder and TruckBuilder extends CarBuilder?
Aucun commentaire:
Enregistrer un commentaire