Intent
Allow an object to easily vary some behavior or property independently of
others.
Solution
- Create an abstract object which provides a common interface for specific
implementations of the variable behavior or property.
- Create concrete objects descended from AbstractObject which implement the
specific behavior or property.
- Define a reference to the AbstractObject in the Client and assign it to
one of the ConcreteObjects at runtime.
- Delegate all operations for the specific behavior or property from the
Client to the SpecificObject using the AbstractObject reference.
Consequences
- Behavior is well encapsulated in objects.
- Results in highly configurable and customizable designs.
- Can add overhead due to pointer indirection.
Related Patterns
Strategy and State are
specialized forms of this pattern
"Relationships between Design Patterns," W. Zimmer, in
Pattern Languages of Program Design (1)
Pattern Languages of
Program Design
1 [Barnes&Noble]