3. The intent of The Decorator pattern referring to GoF book "Attach additional responsibilities to an object dynamically. Decorators provide a flexible alterative to subclassing for extending functionality." Decorators are also known as “wrappers” , because a decorator wraps itself around another object. Today we will discuss why the Decorator design pattern provides a flexible alternative to subclassing as it demonstrates why subclassing can be dangerous. Intent
9. The Open – Closed Principle Design Principle : Classes should be open for extension, but closed for modification. The code should be designed to allow classes to be easily extended to incorporate new behavior (such as adding condiments) without modifying the existing code (such as Espresso). Therefore the design is resilient to change and flexible enough to take on new functionality to meet changing requirements.
10. Meet The Decorator cost() Constructing the above example with the Decorator pattern. Espresso cost() Espresso Mocha cost()