๐Ÿงฉ Design patterns, taught in C++

Design patterns and SOLID principles, in modern C++.

The Gang of Four patterns and the SOLID principles, taught as decisions under forces rather than recipes to apply by reflex, with new, real-domain C++20 and C++23 code behind every chapter and a GoogleTest suite proving each example actually does what the chapter claims. Read it straight through, or jump to the part that answers the question you have right now.

C++20 / C++23 SOLID GoF patterns CMake / Conan GoogleTest

The parts

Twelve parts, read in order the first time. Each part page lists its chapters; each chapter stands on its own for a reader jumping in to solve one problem. The orientation part is the map; start there if you only have time for one page.

Part 0

Orientation

The toolchain (clang, CMake, Conan, GoogleTest), how to read the book, and the codetabs convention that carries C++20 and C++23 side by side through every chapter.

1 chapterExplore โ†’
Part 1

Recognizing Design

Patterns as decisions under forces, not recipes to apply by reflex, and the shared vocabulary a team (and an AI pairing partner) needs to name what it sees.

2 chaptersExplore โ†’
Part 2

Principles (SOLID, Martin)

The five SOLID principles in modern C++ terms: SRP/OCP/LSP first, then ISP/DIP and dependency injection without a framework.

2 chaptersExplore โ†’
Part 3

The C++ Substrate

RAII and deterministic lifetimes, value semantics and smart-pointer ownership, and proving a design works with GoogleTest before the patterns chapters begin.

3 chaptersExplore โ†’
Part 4

Selecting and Varying Behavior

Strategy, Template Method with non-virtual interface, State and finite-state machines (including probabilistic ones), and Command with undo and command queues.

4 chaptersExplore โ†’
Part 5

Creating Objects Under Control

Factory Method and Abstract Factory, Builder and Prototype (with serialization), and Singleton alongside the dependency-injection alternative.

3 chaptersExplore โ†’
Part 6

Composing and Adapting Structure

Adapter, Facade, and Bridge (with PImpl), Decorator and Proxy, and Composite and Flyweight alongside the Null Object idiom.

3 chaptersExplore โ†’
Part 7

Coordinating and Traversing

Observer and Mediator, Chain of Responsibility and Iterator with ranges, and Visitor, Memento, and Interpreter.

3 chaptersExplore โ†’
Part 8

Idiomatic C++ Expressions

CRTP and policy-based design, type erasure alongside PImpl, and expression templates, serialization, and prototype registries.

3 chaptersExplore โ†’
Part 9

Patterns in the Wild

Resource pools (connection, thread, object, monitor, and active object), shortcut patterns such as function-pointer tables and dispatch maps, and anti-patterns to recognize and avoid.

3 chaptersExplore โ†’
Part 10

Changing Inherited Code (Modernized Feathers)

Seams and the test safety net, the 24 dependency-breaking techniques updated for C++20/23, Fowler contrasted and combined with Feathers, and when to refactor versus rewrite.

4 chaptersExplore โ†’
Part 11

Putting It Together

A final project that composes several patterns from the book, and a look at working with AI and LLM tools as a pattern-literate collaborator rather than a code vending machine.

2 chaptersExplore โ†’
Part 12

Appendices

A build and toolchain reference, a GoogleTest reference, a gMock mocking reference, an xUnit test-patterns guide, a pattern-to-force quick reference that maps every pattern, principle, and idiom in the book to the forces it answers, a code-first review of the wider programming-principle vocabulary beyond SOLID, and a C++-specific review of large-scale physical design: components, levelization, and insulation.

7 chaptersExplore โ†’