Decorator Design Pattern

Get an overview of the decorator design pattern.

Overview

Suppose that we’re in a restaurant and order some beverages from a list (coke, coffee, tea). But along with the different drinks, the restaurant also gives us the option of adding ice and lemon to our beverage (with an additional cost).

One way to program this problem would be to create a base class of beverages and inherit multiple classes like Coke, Coke_lemon, Coke_ice, Coffee, Cold_coffee, and so on. Just by looking at the names of the classes, we can see that there will be a problem if the restaurant wants to add more beverages or add-ons. This will ...