Head First Design Patterns - Chapter 3 - The Decorator Pattern
The Decorator Pattern Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
- Identify the aspects of your application that vary and separate them from what stays the same
- Encapsulate what varies
- Favor composition over inheritence (HAS-A can be better than IS-A)
- Program to interfaces, not implementations
- Strive for loosely coupled designs between objects that intract
- Classes should be open for extension but closed for modification