Is the decorator pattern really needed here?

I am learning the decorator design pattern from the Head first design patterns book. Their example treats different types of coffees as a Beverage. The beverages are decorated with things like milk, soy, whip cream etc. For example, the DarkRoast coffee with mocha and whip cream : 

The class diagram : 

I understand that this example is used only because it is simple. But, I have an alternate and simpler way to implement this example without decorator pattern. We can have an Item class with description and cost. Then, the Beverage class can have baseCost, totalCost and list of Items.

Does this alternative design have any major disadvantages over the decorator pattern ? Can you give any specific scenarios where the decorator pattern would be better than my design ?

PS - In case anyone wants to see the decorator code : https://github.com/bethrobson/Head-First-Design-Patterns/tree/master/src/headfirst/designpatterns/decorator/starbuzz

#java #design-pattern

4 Likes3.40 GEEK