Appendix I

The Gang of Four Companion

This appendix demonstrates how informal specifications of some of the design patterns in the seminal Gang of Four catalogue [Gamma et al 1995] can be specified formally using Codecharts. Each section contains a brief description of the pattern, followed by a UML class diagram of the pattern's structure and a Codechart.


See §11.4.


Intent Convert a class's interface to one that a client expects.Participants

  • Target: Defines the interface that Client uses.
  • Client: Collaborates with objects conforming to the Target interface.
  • Adaptee: Defines an existing interface that needs adapting.
  • Adapter: Adapts the interface of Adaptee to the Target interface.

Collaborations Clients call operations on an Adapter instance. In turn, the adapter calls Adaptee operations that carry out the request. The collaboration can take in either one of two forms: In the Adapter (class) variation, the Adapter class inherits from the Adaptee class, and in the Adapter (object) variation, the Adapter class holds a member (field) instance of the Adaptee class.


Figure I-1. UML Class diagram of the structure of the Adapter (class) pattern (adapted from [Gamma et al. 1995] by conversion from the OMT notation)


Codechart 112. Adapter (class) pattern

Figure ...

Get Codecharts: Roadmaps and blueprints for object-oriented programs now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.