Overview
The Decorator pattern provides a flexible alternative to sub-classing for extending functionality. It allows you to add responsibilities to individual objects, not the entire class, at runtime.
Key Concepts
- Component: The interface for objects that can have responsibilities added to them.
- Concrete Component: The original object being decorated.
- Decorator: Maintains a reference to a Component object and defines an interface that conforms to Component's interface.
- Concrete Decorators: Add responsibilities to the component.
Benefits
- More flexible than static inheritance.
- Avoids feature-laden classes high up in the hierarchy.