Decorator Pattern
The Decorator pattern allows behavior to be added to individual objects, dynamically, without affecting the behavior of other objects from the same class.
When to Use:
Use the Decorator pattern when you need to add responsibilities to objects without modifying their code.
Example
Pros:
- Extends functionality without modifying existing code.
- Combines behaviors in a flexible and reusable way.
Cons:
- Can result in many small objects, leading to complexity.
- Harder to debug because of many layers of decorators.