bigonotes
CS ConceptsDesign Patterns

The Gang of Four (GoF)

Who the Gang of Four were, the 23 patterns they cataloged, and which ones you'll meet in modern code.

5 min readLast updated

In 1994 four authors published Design Patterns: Elements of Reusable Object-Oriented Software, which cataloged 23 patterns and gave the industry a shared design vocabulary. They're called the Gang of Four (GoF) because there were four of them. When people say "the classic design patterns", they usually mean this list. Knowing where the names come from helps you read older code, docs and interview questions that use them.

The authors#

The four authors came from both industry and academia.

Author Background
Erich Gamma Swiss computer scientist; later co-created JUnit, led development tools at Eclipse, and works at Microsoft on VS Code
Richard Helm Worked at IBM Research; brought an industry perspective
Ralph Johnson Professor at the University of Illinois; the academic of the group
John Vlissides Worked at IBM Research and wrote widely on applying patterns well; died in 2005

They kept seeing the same problems and the same solutions across object-oriented systems, but nobody had shared names for them. So they cataloged them. The book was published by Addison-Wesley in October 1994.

What made the book influential#

Plenty of books describe good design. Three choices made this one last.

  1. They discovered rather than invented. The patterns already existed in real code. GoF named and documented them, like biologists cataloging species.
  2. They used a consistent template. Name and classification, intent, also known as, motivation, applicability, structure, participants, collaborations, consequences, implementation, sample code, known uses, related patterns. See How to Read a Design Pattern.
  3. They gave developers a language. Before: "I made a class with a private constructor that returns the same instance every time..." After: "I used a Singleton."

The 23 patterns#

Here is the catalog itself. The book groups its patterns into three families by the problem they solve, and the analogy column gives you a quick way to remember each one.

Creational (5): how objects are created#

# Pattern Analogy Typical use
1 Singleton One president per country Shared config, connection pool
2 Factory Method Each pizza franchise makes its own style Creating platform-specific UI buttons
3 Abstract Factory A furniture line where every piece matches Cross-platform UI toolkits
4 Builder Assembling a sandwich step by step SQL query builders
5 Prototype Cloning Spawning many similar game enemies

Structural (7): how objects are connected#

# Pattern Analogy Typical use
6 Adapter Travel power-plug adapter Wrapping a third-party library
7 Bridge One remote, many devices Database drivers
8 Composite Folders inside folders File systems, UI trees
9 Decorator Coffee with add-ons Buffered I/O streams (io.BufferedReader)
10 Facade A restaurant waiter Simplifying a complex API
11 Flyweight Chess pieces sharing one icon Characters in a text editor
12 Proxy A credit card standing in for your bank account Lazy-loading images

Behavioral (11): how objects communicate#

# Pattern Analogy Typical use
13 Chain of Responsibility Approval chain in a company Middleware pipelines
14 Command A restaurant order ticket Undo/redo
15 Interpreter Translating a language Parsing small languages (regex, query DSLs)
16 Iterator Channel up/down on a TV remote for-each loops
17 Mediator Air traffic control Chat room server
18 Memento Game save points Undo snapshots
19 Observer Newsletter subscription Event listeners
20 State Music player modes TCP connection states
21 Strategy Choosing how to travel Pluggable sorting or pricing
22 Template Method A recipe with variations Framework hooks
23 Visitor A health inspector visiting each restaurant Compiler passes over an AST

Before and after GoF#

The third point above, the shared language, is the book's biggest legacy. Here's how it changed the way developers talk about design.

Before (pre-1994) After
No common vocabulary; same solutions, different names A shared language for design
Knowledge was hard to share Faster communication and onboarding
Books explained how but rarely why Clear problem → solution → trade-off mapping

How the patterns fare today#

Thirty years on, not all 23 patterns get equal use. Here's roughly how they sort out.

Used constantly: Iterator (built into most languages), Observer (every GUI and event system), Factory Method, Strategy, Singleton.

Most misused:

  • Singleton, which creates hidden global dependencies.
  • Factory, which over-engineers simple object creation.

Rarely hand-written: Interpreter (narrow use case), Visitor (flexible but complex), Flyweight (only worth it with very large numbers of objects).

Criticisms worth knowing:

  • Some patterns are workarounds for missing language features. First-class functions make Strategy and Command much lighter, for example.
  • Applied blindly, patterns lead to over-engineering.
  • The 1994 examples feel dated.

The core problems haven't changed, though, and the names are still the common vocabulary.

You already use GoF patterns#

Many of the patterns in the "used constantly" group are built into Python, so you use them without naming them. Each comment below points out one:

import io
import logging
from abc import ABC, abstractmethod

names = ["bob", "Alice", "carol"]

# Iterator: every for loop walks an iterator
for name in names:
    print(name)

# Observer: a logger notifies every handler attached to it
logger = logging.getLogger("app")
logger.addHandler(logging.StreamHandler())
logger.warning("disk almost full")

# Decorator: BufferedReader wraps a raw stream and adds buffering
raw = io.BytesIO(b"hello")
reader = io.BufferedReader(raw)

# Strategy: the comparison (key function) is passed in
names.sort(key=str.lower)


# Template Method: the base class fixes the order of steps
class Game(ABC):
    @abstractmethod
    def initialize(self) -> None: ...

    @abstractmethod
    def start_play(self) -> None: ...

    @abstractmethod
    def end_play(self) -> None: ...

    def play(self) -> None:  # subclasses shouldn't override this
        self.initialize()
        self.start_play()
        self.end_play()

Key takeaways#

  • GoF = Gamma, Helm, Johnson, Vlissides; their 1994 book cataloged 23 patterns.
  • The split is 5 creational, 7 structural, 11 behavioral.
  • They documented existing practice and gave it names and a consistent template.
  • A small subset (Iterator, Observer, Factory, Strategy, Singleton, Decorator) covers most everyday code.
  • Modern languages make some patterns lighter, but the vocabulary still matters.
Revision notes · 1 min

Core idea#

The Gang of Four are Gamma, Helm, Johnson and Vlissides. Their 1994 book Design Patterns cataloged 23 patterns and gave developers a shared design vocabulary.

Key points#

  • They discovered the patterns in existing code. They did not invent them.
  • Each pattern follows one consistent template: intent, motivation, applicability, structure, participants, consequences, and more.
  • The names became a language. "I used a Singleton" replaces a paragraph of explanation.
  • The split is 5 creational, 7 structural, 11 behavioral.

The 23 patterns#

Family Question Patterns
Creational (5) How objects are created Singleton, Factory Method, Abstract Factory, Builder, Prototype
Structural (7) How objects are connected Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy
Behavioral (11) How objects communicate Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor

How they fare today#

Group Patterns
Used constantly Iterator, Observer, Factory Method, Strategy, Singleton
Most misused Singleton (hidden globals), Factory (over-engineering)
Rarely hand-written Interpreter, Visitor, Flyweight
  • Python builds several in: every for loop (Iterator), logger handlers (Observer), io.BufferedReader (Decorator), sort(key=...) (Strategy).

Criticisms#

  • Some patterns work around missing language features. First-class functions make Strategy and Command much lighter.
  • Applied blindly, patterns lead to over-engineering.
  • The 1994 examples feel dated. The core problems and the names still hold.

Say it in an interview#

  • "GoF cataloged 23 patterns in 1994: 5 creational, 7 structural, 11 behavioral."
  • "A small subset covers most everyday code: Iterator, Observer, Factory, Strategy, Singleton, Decorator."

Found a mistake? Email ask@bigonotes.com