The Gang of Four (GoF) catalogue, published in 1994 by Gamma, Helm, Johnson, and Vlissides, defines 23 reusable object-oriented design patterns across three categories: Creational, Structural, and Behavioral. These patterns represent solutions to recurring design problems, providing a shared vocabulary that accelerates team communication. Modern frameworks embed GoF patterns deeply — Angular's Dependency Injection is Factory + Strategy; React's Context API is Observer; Java's Stream API is Iterator + Decorator.

Key Points

  • Creational patterns (5) abstract object creation, decoupling instantiation from client code — Singleton, Factory, Abstract Factory, Builder, Prototype.
  • Structural patterns (7) compose objects and classes into larger structures — Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy.
  • Behavioral patterns (11) manage algorithms and object communication — Chain of Responsibility, Command, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor, Interpreter.
  • Strategy pattern enables runtime algorithm swapping without modifying the context — used heavily in sorting, pricing engines, and authentication pipelines.
  • Observer pattern is the backbone of reactive systems: RxJS, EventEmitter, and DOM events all implement it.
  • Decorator pattern composes behavior without inheritance — Python's @decorator syntax and Java's InputStream chain are canonical examples.
  • Singleton is the most misused pattern — often replaced by DI container-managed scoped instances to avoid global state and testing difficulties.
  • Prefer composition over inheritance (Decorator, Strategy, Composite) — GoF itself advocates this in its design principles.
CategoryKey PatternsOne-Line Purpose
CreationalSingletonEnsure exactly one instance of a class exists globally
CreationalFactory MethodDelegate object creation to subclasses or factory functions
CreationalBuilderConstruct complex objects step by step with a fluent API
StructuralAdapterConvert one interface to another that clients expect
StructuralDecoratorAdd responsibilities to objects dynamically without subclassing
StructuralProxyControl access to an object (lazy init, caching, access control)
BehavioralObserverDefine a one-to-many dependency so dependents are notified on state change
BehavioralStrategyDefine a family of algorithms and make them interchangeable at runtime
BehavioralCommandEncapsulate a request as an object, enabling undo/redo and queuing

Real-World Example

Spring Framework is a GoF pattern showcase: BeanFactory (Factory), ApplicationContext (Facade), JdbcTemplate (Template Method), AOP proxies (Proxy + Decorator), and Spring Events (Observer). Understanding GoF is a prerequisite for deep framework internals knowledge.