GoF Design Patterns Reference

All 23 Gang of Four patterns with intent and when-to-use, grouped into creational, structural and behavioral

Searchable Gang of Four design pattern reference: all 23 creational, structural and behavioral patterns with their intent and the situation each one solves, so you can pick the right pattern by problem.

What are the three categories of GoF patterns?

Creational patterns abstract how objects are made (Factory, Builder, Singleton, Prototype, Abstract Factory). Structural patterns compose objects into larger structures (Adapter, Decorator, Facade, Proxy, Composite, Bridge, Flyweight). Behavioral patterns assign responsibilities and manage communication between objects (Observer, Strategy, Command, State, and seven more), for 23 patterns in total.

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.