In the book "Head first design patterns (2014, 2nd edition)" in the chapter about the decorator pattern the authors take the instance variable Beverage beverage from the 4 condiment classes (Milk, Mocha, Soy, Whip) and put it into the abstract class CondimentDecorator. (see page 110, the solution to the getSize()-question)
public abstract class CondimentDecorator extends Beverage{
public Beverage beverage;
public abstract String getDescription();
public Size getSize(){
return beverage.getSize();
}
}
What is the reason for doing this? Do they do it in order to save some code lines, since now the condiments dont need to declare their own instance variable since they inherit it from the abstract class?
UML diagram for the coffe shop BEFORE they move the instance variable:
Aucun commentaire:
Enregistrer un commentaire