Brief Overview:

|
Allows new or additional behavior to be added to an existing object dynamically
at run time. We say that the new behavior "decorates" the existing object.
This requires some groundwork to be done at design time. The additional behavior
classes are made subclasses of a "decorator" class which is itself also a sub-class
of the object (or its parent class) they are to decorate. The decorator class has
added a pointer to the parent class of the object type that it decorates. The
decorator is then instantiated by passing a pointer to the object it will decorate.
The decorator then receives function calls meant for the object and either passes the
calls on to the object or modifies the behavior as required for the object. The way
it is organized multiple decorators can be "stacked" or "nested" to add more behavior
patterns. This is an alternative to adding extra behavior by adding more sub-classes.
Java I/O streams actually follow this pattern.
|