Loading content...
The Gang of Four didn't simply compile a list of patterns—they curated a carefully selected catalog that represents the essential building blocks of object-oriented design. The 23 patterns they documented emerged from extensive study of successful systems, academic research, and industrial practice. Each pattern was included only after demonstrating its utility across multiple, independent codebases.
These 23 patterns have become the lingua franca of software design. When a developer in Tokyo says "Observer pattern" to a developer in Berlin, both understand exactly what structure is being described. This shared vocabulary is perhaps the GoF book's greatest contribution—it transformed design discussions from lengthy explanations into precise, efficient communication.
In this page, we'll survey all 23 patterns, organized by their categories: Creational, Structural, and Behavioral. For each pattern, you'll learn its core purpose, when to apply it, and how it relates to others in the catalog.
By the end of this page, you will have a mental map of all 23 GoF patterns—their categories, their purposes, and their relationships. This overview prepares you for the detailed pattern-by-pattern study in subsequent chapters, giving you context for where each pattern fits in the larger design landscape.
The Gang of Four organized their patterns into three categories based on what aspect of software design each pattern addresses. Understanding these categories helps you navigate the catalog and identify which patterns might solve a given problem.
Creational Patterns deal with object creation mechanisms. They abstract the instantiation process, making systems independent of how their objects are created, composed, and represented. In essence, they answer the question: How should objects be created?
Creational patterns become important when systems depend on object composition more than class inheritance. As systems evolve to favor composition, correctly instantiating composed objects becomes crucial.
Structural Patterns concern object composition and relationships. They describe how objects and classes can be combined into larger structures while keeping these structures flexible and efficient. They answer: How should objects be composed into larger structures?
Structural patterns help you realize new functionality by composing objects in ways that leverage their individual capabilities.
Behavioral Patterns focus on algorithms and the assignment of responsibilities between objects. They characterize complex control flow that's difficult to follow at runtime. They answer: How should objects interact and distribute responsibilities?
Behavioral patterns shift your focus from understanding control flow to understanding how objects interconnect.
| Category | Focus | Key Question | Pattern Count |
|---|---|---|---|
| Creational | Object creation mechanisms | How should objects be created? | 5 patterns |
| Structural | Object composition | How should objects compose into structures? | 7 patterns |
| Behavioral | Object interaction & responsibility | How should objects interact? | 11 patterns |
When facing a design problem, first identify which category it falls into. If you're struggling with object creation complexity, look at Creational patterns. If you're composing objects into larger structures, consider Structural patterns. If you're dealing with complex interactions or responsibility assignment, explore Behavioral patterns.
Creational patterns abstract the instantiation process. They help make a system independent of how its objects are created, composed, and represented. A system configured with creational patterns knows which objects it works with, but the patterns encapsulate knowledge about which concrete classes the system uses and how instances are created and combined.
Creational patterns become increasingly important as systems evolve toward object composition. Hard-coding a class name commits you to a particular implementation. Creational patterns provide flexibility by letting you defer the decision of which object to create to runtime, to a configuration, or to another part of the system.
The Five Creational Patterns:
Abstract Factory is often implemented with Factory Methods, and can be implemented with Prototype. Builder and Prototype can both be used with Singleton. Factory Method is often called from Template Method. These patterns can be combined and substituted based on your specific flexibility needs.
Structural patterns concern how classes and objects are composed to form larger structures. Structural class patterns use inheritance to compose interfaces or implementations, while structural object patterns describe ways to compose objects to realize new functionality.
The key insight of structural patterns is that simple objects can be combined in sophisticated ways. Rather than creating complex classes with extensive functionality, structural patterns show how to assemble objects such that the composition exhibits desired behavior.
The Seven Structural Patterns:
Adapter changes the interface of an object while Decorator adds responsibilities—but both wrap objects. Composite and Decorator have similar structures but different intents. Bridge is often combined with Abstract Factory to create implementations. Facade often works alongside Adapter, Decorator, and Proxy.
Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects. They describe not just patterns of objects or classes but also the patterns of communication between them. They shift your focus from static structure to dynamic, runtime behavior.
Behavioral patterns characterize complex control flow that's difficult to follow at run-time. They help you analyze a system's behavior by focusing on how objects cooperate, rather than tracing through execution paths.
Behavioral class patterns use inheritance to distribute behavior between classes. Behavioral object patterns use object composition to achieve flexible runtime behavior. Object composition allows behavior to be determined dynamically.
The Eleven Behavioral Patterns:
Strategy and State have nearly identical structures but different intents. Command can use Memento for undo. Iterator often uses Memento to store traversal state. Composite is often traversed using Visitor. Mediator and Observer are both about coordinating multiple objects. Template Method often calls Factory Methods.
Individual patterns solve individual problems. But real systems face multiple design challenges simultaneously. Skilled designers combine patterns, using each where appropriate, to create comprehensive solutions.
The GoF book demonstrates this explicitly with its Lexi case study—a document editor designed throughout Chapter 1 using multiple patterns:
| Pattern Pair | How They Work Together |
|---|---|
| Abstract Factory + Prototype | Abstract Factory implemented with cloning from prototype instances |
| Composite + Visitor | Visitor traverses composite structure to perform operations |
| Command + Memento | Command stores mementos for undo operations |
| Decorator + Strategy | Decorator adds behavior; Strategy swaps algorithms |
| Observer + Mediator | Mediator centralizes Observer relationships |
| Builder + Composite | Builder constructs complex composite structures |
| State + Flyweight | State objects shared as flyweights across contexts |
Christopher Alexander's original idea was a 'pattern language'—patterns that work together to solve problems in a domain. The GoF patterns form such a language for object-oriented design. As you gain experience, you'll recognize not just individual patterns, but how they combine into larger solutions.
With 23 patterns, how do you find the right one for your problem? The GoF book provides several entry points:
By Intent: Each pattern has a one-sentence intent statement. Scanning these can quickly narrow down candidates.
By Problem: What design challenge are you facing?
By Variation: What aspects of the design might change?
A common mistake is searching for a pattern to apply, rather than recognizing a problem that a pattern solves. Patterns should emerge from your analysis of design challenges, not be imposed because you know them. If you find yourself looking for places to apply the Visitor pattern, you're approaching design backwards.
The Pattern Selection Process:
Let's consolidate what we've learned about the 23 Gang of Four patterns:
What's Next
Now that you have a map of all 23 patterns and their purposes, we'll explore the pattern documentation format that the Gang of Four established. Understanding this format—Intent, Motivation, Structure, Consequences, and more—will help you read pattern descriptions effectively and eventually document patterns of your own.
You now have a comprehensive overview of all 23 Gang of Four patterns. You understand their categories, can identify their purposes, and recognize how they work together. This foundation prepares you for the detailed pattern studies ahead.