Decorator Pattern

(from Design Patterns)

Synopsis

Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extended functionality.

Context

You want to layer additional capability onto an object. However, the additional capabilities you want are highly variable.

Forces

Solution

Enclose the subject in another object, the decorator object, which conforms to the same interface. This makes the decorator transparent to clients.

The decorator forwards requests to the subject while performing additional actions before and after forwarding.

Consequences

Implementation

See Design Patterns for sample code.

Known Uses


Thomas Minka
Last modified: Wed Mar 27 14:34:24 EST 2002