Skip to main content

The “Gang of Four” Decorator Pattern: What Is Its Appropriate Use?

Printer-friendly version

Version of 22 February 2010

In discussions on PSDN1 reference has been made to the use of the Decorator pattern as a mechanism in the Progress Professional Services Model-Set-Entity (M-S-E) pattern for creating subtypes of Business Entities. Decorator is proposed as an alternative to the use of Generalization and Delegation. There are really two separate issues in this discussion. One issue is whether the pattern proposed in M-S-E is to be preferred generally for creating subtypes, or, if not generally, under what circumstances should it be preferred? The other issue relates to whether such usage was intended by the Gang of Four2 when they described the Decorator pattern. Because this latter issue seems to have been one which has incited strong conflicting opinions, the present whitepaper has been created to review the text of the Gang of Four description of Decorator with the goal of illuminating the intended use. This is a separate issue from the virtues of the pattern used in Model-Set-Entity, which will be discussed separately3.

This discussion will simply review the text of the Decorator pattern as expressed in the book, extracting quotes as appropriate, and discussing the possible apparent meanings. Section headers correspond to the sections of the pattern presentation in the book. The comparison with respect to handling subtypes will be to Generalization and Delegation4. Generalization refers to decomposing responsibilities into common responsibilities, typically in the form of a superclass, and type specific behavior, typically in the form of multiple subclasses of that superclass. Delegation refers to identifying cohesive units of responsibility and separating that responsibility into its own class such that the Delegate assumes the responsibility for some area in support of the primary class with which it is associated. The two can be used in combination, i.e., a Delegate may itself be a superclass with a number of subclasses, representing subtypes of the general area of responsibility of the Delegate. Generalization and Delegation are design-time decisions and thus static. I.e., any given object must be of one specific subtype and must be associated with any required Delegates.

GoFDecorator_20100222.pdf127.66 KB