The Gang of Four book (Gamma, Helm, Johnson, Vlissides, 1994) catalogued 23 reusable solutions to recurring object-oriented design problems. Knowing them gives you a shared vocabulary and a head start on structuring code. This reference lists every pattern with its intent and the situation it addresses.
How it works
The 23 patterns split into three families:
- Creational (5) — control object creation: Abstract Factory, Builder, Factory Method, Prototype, Singleton.
- Structural (7) — compose objects and classes: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy.
- Behavioral (11) — manage algorithms and responsibilities: Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor.
For each, read the intent (what it achieves) and the when note (the problem that justifies it). Match the problem first, then apply the pattern.
Example
You need to add logging and compression to a data stream without subclassing
every stream type for every combination. That is the Decorator problem: wrap
the stream in a LoggingStream, then wrap that in a CompressingStream, each
adding one responsibility and forwarding the rest. The combinations multiply at
runtime, not through a class explosion.
Notes
- Patterns describe relationships and intent, not specific code — the same pattern looks different across languages.
- Several patterns overlap by structure but differ by intent (Adapter vs Decorator vs Proxy all wrap an object).
- Modern languages bake some patterns in: first-class functions make Strategy and Command lightweight, and iterators are built into most standard libraries.
- Over-applying patterns is a smell of its own — see the SOLID, KISS and YAGNI principles for the counterweight.