In many examples about builder design patterns, there is one example that makes me confused, the build method calls the house setter to set the value into the house object attribute.
class IglooHouseBuilder implements HouseBuilder
{
private House house;
public IglooHouseBuilder()
{
this.house = new House();
}
public void buildBasement()
{
house.setBasement("Ice Bars");
}
public void buildStructure()
{
house.setStructure("Ice Blocks");
}
public void buildInterior()
{
house.setInterior("Ice Carvings");
}
public void buildRoof()
{
house.setRoof("Ice Dome");
}
public House getHouse()
{
return this.house;
}
}
if we can use the setter to set some value why do we need to use a builder design pattern? doesn't setter can also solve the telescoping constructor problem?
source : https://www.geeksforgeeks.org/builder-design-pattern/
Aucun commentaire:
Enregistrer un commentaire