Design patterns and SOLID principles, in idiomatic Python.
The Gang of Four patterns and the SOLID principles, sorted three
ways: the patterns that dissolve into Python language features,
the patterns that survive as design decisions, and the names that
need disambiguating, headlined by the Decorator pattern and the
@decorator syntax. Each pattern is taught as a
decision under forces, with new shipping-domain Python 3.15 code
behind it and a pytest suite, checked by mypy in strict mode,
proving each example does what the chapter claims. Read it
straight through, or jump to the part that answers the question
you have right now.
The parts
Fourteen parts and the appendices, 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 first part sets up the toolchain every example runs on.
Orientation
The toolchain every example runs on (uv, ruff, mypy, pytest) and the consignment example that proves it works.
Why This Is Not a GoF Retelling
Patterns as decisions under forces, and the claim that several 1994 catalogue entries are now Python language features rather than designs you write.
Why Python Is Different
The map that sorts every catalogue pattern into those a language feature dissolves, those that remain design, and those whose name means two things in Python, followed by naming patterns so that teams and AI assistants read the same contract.
Principles: SOLID
The five SOLID principles in Python: single responsibility, open/closed and Liskov substitution, then interface segregation and dependency inversion without a framework.
The Python Substrate
The data model and dunder methods, dataclasses and value semantics, Protocol and structural typing with mypy, context managers, and proving a design works with pytest, pytest-mock, and mypy.
Selecting and Varying Behaviour
Strategy as a callable, Template Method and its function alternative, State and finite state machines, and Command with undo and command queues.
Creating Objects Under Control
Factory Method and Abstract Factory, Builder with dataclasses and Prototype, and Singleton as a module, a Borg, or a metaclass.
Composing and Adapting Structure
Adapter, Facade, and Bridge; the Decorator pattern told apart from the @decorator syntax, with Proxy; and Composite with Flyweight.
Coordinating and Traversing
Observer, Mediator and Chain of Responsibility, Iterator through generators and the iterator protocol, and Visitor, Memento, and Interpreter.
Idiomatic Python
Decorators done right, descriptors and properties, singledispatch, metaclasses and __init_subclass__, and dynamic attributes with __getattr__.
Patterns in the Wild
The shortcuts Python offers in place of full patterns (dict dispatch, function tables, EAFP) and the anti-patterns that come from misusing the catalogue.
Changing Inherited Code
Seams in Python, dependency-breaking techniques, Fowler and Feathers contrasted and combined, and the decision between refactoring and rewriting.
Concurrency
Two chapters on the GIL and performance, and on how asyncio reshapes the patterns.
Putting It Together
A final project that combines the patterns, and working with AI and LLM tools on pattern-heavy code.
Appendices
Reference material: build and toolchain, pytest, mocking, xUnit test patterns, a pattern-to-force quick reference, and programming principles reviewed in code.
Everything else on the site
Beyond the chapters, the site carries the runnable examples, the diagrams, and the bibliography.