Decorator pattern (source code)

= Decorator pattern

Represent an optional responsibility by an object implementing the same interface as its wrapped component. The wrapper delegates existing work and adds its own behavior. Independent responsibilities can then be assembled as a chain instead of defining a concrete class for every subset of options. <Structural induction> on the chain proves accumulated behavior, provided each wrapper preserves the base interface contract.