Origin: |
GoF 95 |
Reason: |
Extend the functionality of an instance of a class,
but not of all instances of the class.
|
Synopsis: |
Define a class, the Decorator, that encloses
the object whose functionality is to be extended.
|
Example: |
Consider a security and monitoring system.
When the object controlling a door receives a request to open a door,
the monitor controlling the door displays the doorway.
There are several classes for opening a door and
several classes for displaying a doorway.
|
Solution: |
Service |
There is both an interface and one or more concrete classes.
Objects of these classes provide a service.
|
Doorway monitor |
Wrapper |
There is both an interface and one or more concrete classes.
Objects of these classes delegate operations to Service.
|
Door opener |
|
See also: |
Delegation
(the Decorator pattern uses delegation)
|