Introduction

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

Participants:

Component

Concrete component

Decorator

In the Attribute field you can specify the name of a Decorator's attribute where it keeps a reference to a Component object.

The Initialization variant option defines the kind of initialization of that attribute.

Concrete decorator

If Copy documentation is checked, it copies Javadoc comments from methods in interfaces participating in the pattern to the stubs of these methods that the pattern created in classes implementing such interfaces.

If Create pattern links is checked, it generates additional links that can be used by this pattern later to determine classes and interfaces participating in the pattern. This means that if you check this option and use the pattern to create a set of classes and interfaces, the pattern invoked for some participant later (using the Choose Pattern command on the right-click menu) will automatically find all other participants (if possible) and fill in participant fields with their names.

Furthermore, if you apply the pattern with this option checked and later invoke the pattern using the Choose Pattern command on the right-click menu for some participant, the pattern has an additional field called Use selected class as, containing possible roles for the selected element.

This option is very useful when you are planning to change something in the classes/interfaces participating in the pattern. For example, if this option is on and after creating the classes and interfaces you add several methods to a certain interface-participant (and this change must be reflected somehow in other participants), all you need to do is select this changed interface, invoke the Choose Pattern dialog for this element and select the original pattern. After that the pattern determines other participants and you only need to click Finish. The pattern will modify all other classes and interfaces according to your changes.

Applicability

Use the Decorator pattern

Documentation of OCL-Schemata