Applied Design Patterns with Java

Structural :: Decorator (175) {C ch 12}


Example - UML : CoolSlash


Example - Java :: Patterns\Structural\Decorator

Pattern Concept: to provide a way to dynamically modify the behavior of individual objects by attaching additional responsibilities without having to create a new derived class. Decorators provide a flexible alternative to subclassing for new functionality.


Issues and Consequences of the
Decorator pattern include:

The first set of example Java programs show decorating GUI buttons; they are named 'decoWindow', 'slashWindow', and 'borderWindow'.

The UML diagram is above, and the list of Java files is below:


The second example Java program is are 'DecoStream' and it shows the decorating of non-visual object methods (read()) by intercepting and forwarding them.

The UML diagram is above, and the list of Java files is below:

Catalog Structural Prev Next