Originally posted by Chunnard Singh:
they will all be true?
It's unlikely that all of them will be true. Someone may want a HouseBlend "Black" (i.e. no condiments whatsoever) in which case all of them are false. it is also unlikely that someone will want soy and milk in the same beverage.
If anything you could complain that those properties shouldn't be boolean - they should be a quantity. A milk shot into a standard
coffee isn't going to cost as much as the milk in a latte, which consist 2/3 of milk.
This particular domain model assumes that the cost for each condiment is constant across all beverages - but only the condiments that are used in the preparation of a particular beverage are factored into the cost.
Also where are variables like milkCost,soyCost,mochaCost coming from?
I presume those are private attributes of the Beverage class that represent the cost of each condiment (if it is used in the beverage preparation) - they could even be private constants. To reduce clutter you typically only show public methods and attributes in UML. If you need to show more then you use prefixes: "+" for public, "#" for protected, and "-" for private.
This way only the Beverage class needs to know the cost of all the possible condiments. Meanwhile the subclasses only need to know their own basic cost and which condiments need to be added. - its the Beverage class that calculates the combined cost of those condiments.
Also remember that this has got nothing to do with the decorator
pattern. It merely sets the stage to replace this design with decorators.