OO Reuse Mechanisms: Inheritance, Composition, Delegation, and Designing for Change

This section from the GoF *Design Patterns* book covers the fundamental mechanisms for achieving reuse in object-oriented systems — class inheritance vs. interface inheritance, composition vs. inheritance, delegation, and parameterized types — and then catalogs common causes of redesign with the patterns that address each. It also distinguishes three levels of software reuse: application programs, toolkits, and frameworks.

Key Concepts

Commands and Syntax

No commands per se, but key design techniques with examples:

1. Subclass override (Template Method)

2. Pass a strategy object (Strategy)

3. C++ template / Ada generic parameter

Relationships

1. Creating by specifying class explicitly → Abstract Factory, Factory Method, Prototype

2. Dependence on specific operations → Chain of Responsibility, Command

3. Platform dependence → Abstract Factory, Bridge

4. Dependence on representations/implementations → Abstract Factory, Bridge, Memento, Proxy

5. Algorithmic dependencies → Builder, Iterator, Strategy, Template Method, Visitor

6. Tight coupling → Abstract Factory, Bridge, Chain of Responsibility, Command, Facade, Mediator, Observer

7. Extending by subclassing → Bridge, Chain of Responsibility, Composite, Decorator, Observer, Strategy

8. Inability to alter classes → Adapter, Decorator, Visitor

Exam-Relevant Points