Cover of Design Patterns by the Gang of Four, showing abstract interlocking geometric shapes symbolising structured software composition

Pages

512

Published

1995

Design Patterns

Elements of Reusable Object-Oriented Software

Learn the 23 canonical design patterns that let you write flexible, reusable object-oriented code the way experienced architects actually think.

First published in 1994, this book by Gamma, Helm, Johnson, and Vlissides codified the vocabulary of object-oriented design. The 23 patterns documented here — from Singleton and Factory Method to Observer and Visitor — remain the shared language of software engineers across every mainstream language and platform. If you read one book on software architecture, this is the one practitioners have pointed to for three decades.

About this book

Software design is hard. Not because writing code is hard, but because writing code that other people can extend, reuse, and reason about without breaking everything else is hard. The Gang of Four identified that experienced designers repeatedly reach for the same structural solutions — and that naming those solutions gives teams a shared vocabulary that accelerates design conversations and code reviews alike.

This book documents 23 patterns organised into three families: Creational patterns (how objects are constructed), Structural patterns (how objects are composed), and Behavioral patterns (how objects communicate). Each pattern gets a rigorous treatment: intent, motivation, a concrete UML structure, participants, collaborations, consequences, implementation notes, and at least one worked example in C++ and Smalltalk.

The patterns themselves have outlasted the example languages by decades. Developers today apply Decorator in Python middleware, Observer in JavaScript event systems, Strategy in Go service configurations, and Command in distributed task queues. The abstractions are language-agnostic even if the sample code is not.

  • Creational: Abstract Factory, Builder, Factory Method, Prototype, Singleton
  • Structural: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy
  • Behavioral: Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor

Beyond the catalogue, the opening chapters on object-oriented design principles — design to interfaces, favour composition over inheritance, program to an abstraction — are as practically relevant now as they were at publication. The closing chapter on selecting and applying patterns teaches you how to think about design trade-offs, not just copy-paste solutions.

If your codebase is riddled with conditionals that should be polymorphism, inheritance chains that should be composition, or tightly coupled components that make testing painful, the vocabulary and structure in this book will show you exactly what to reach for instead.

🎯 What you'll learn

  • Recognise the structural shape of each of the 23 patterns and know when a problem calls for one.
  • Apply Creational patterns to decouple object construction from the code that uses the resulting objects.
  • Compose Structural patterns to add responsibilities and adapt interfaces without modifying existing classes.
  • Implement Behavioral patterns to distribute responsibility cleanly across collaborating objects.
  • Evaluate trade-offs between patterns that solve similar problems, such as Strategy versus Template Method.
  • Design to interfaces and favour composition over inheritance in ways that keep systems extensible.
  • Communicate design intent clearly using a vocabulary that senior engineers across languages already share.

👤 Who is this book for?

  • Object-oriented programmers who want a rigorous, shared vocabulary for discussing and documenting design decisions.
  • Mid-level engineers moving toward senior roles who need to reason about architecture, not just individual functions.
  • Technical leads who want a common reference their teams can point to during code reviews and design discussions.
  • Self-taught developers who have picked up patterns piecemeal and want the canonical, structured treatment.
  • Computer science students and graduates preparing for system design interviews where pattern knowledge is tested directly.

Table of contents

  1. 01

    Introduction to Design Patterns

    Establishes what a design pattern is, how patterns are described, and why a shared pattern vocabulary matters. Introduces the core object-oriented design principles — program to an interface, favour composition over inheritance — that underpin every pattern in the book.

  2. 02

    A Case Study: Designing a Document Editor

    Walks through a non-trivial design problem end to end, applying multiple patterns to solve concrete problems around document structure, formatting, and user interaction. Shows how patterns interact in a realistic system rather than in isolation.

  3. 03

    Creational Patterns

    Covers the five Creational patterns — Abstract Factory, Builder, Factory Method, Prototype, and Singleton — with worked examples showing how each decouples the creation of objects from the code that depends on them.

  4. 04

    Structural Patterns

    Documents the seven Structural patterns — Adapter, Bridge, Composite, Decorator, Facade, Flyweight, and Proxy — explaining how each controls the composition of classes and objects to form larger, more flexible structures.

  5. 05

    Behavioral Patterns

    Presents all eleven Behavioral patterns, from Chain of Responsibility through Visitor, detailing how each distributes responsibility and communication among objects to keep individual classes focused and independently testable.

  6. 06

    Selecting and Applying a Pattern

    Provides practical guidance on how to identify which pattern fits a given design problem, how to avoid over-engineering, and how to adapt a canonical pattern to the constraints of your own codebase.

Frequently asked questions

Do I need to know C++ or Smalltalk to get value from this book?

No. The examples are written in C++ and Smalltalk, but the patterns themselves are language-agnostic. Most readers today translate the concepts directly into Python, Java, C#, TypeScript, or Go without difficulty.

Is this book still relevant in 2024?

Yes. The patterns document recurring structural problems in object-oriented design that have not changed. What has changed is the languages and frameworks you apply them in, which the patterns accommodate because they describe intent and structure rather than syntax.

What programming experience do I need before reading this?

You should be comfortable writing object-oriented code in at least one language and have some exposure to class hierarchies and interfaces. The book is not an introduction to OOP — it assumes you already write it and want to write it better.

Does this book include companion code or a downloadable code repository?

The original 1995 edition does not include a companion repository. The code examples are printed in the book. Community implementations of all 23 patterns exist in virtually every popular language and are easy to find through a web search.

How does this book compare to Head First Design Patterns?

This book is the original, rigorous academic treatment with precise structure and C++ examples. Head First Design Patterns is a more approachable, Java-based introduction. Many developers read both — this one first for depth, or after for the formal reference.

Is this suitable for developers who primarily write functional or procedural code?

The patterns assume an object-oriented context and are less directly applicable to purely functional programming. That said, understanding the underlying intent of each pattern is useful even if you translate the solution into a different paradigm.

You might also like

📬 Weekly Newsletter

Stay ahead of the curve

Get the best programming tutorials, data analytics tips, and tool reviews delivered to your inbox every week.

No spam. Unsubscribe anytime.