Design patterns
The 22 patterns from “Design Patterns” (Gamma, Helm, Johnson, Vlissides) in three groups. Each topic has an article with code in several languages or is in progress.
Creational patterns
- Factory Method
Subclasses decide which concrete object gets created; callers depend only on a shared interface.
- Abstract Factory
Produces families of related objects that are guaranteed to work together.
- Builder
Assembles a complex object step by step, keeping construction separate from the final result.
- Prototype
New objects are made by cloning an existing instance instead of building them from scratch.
- Singleton
Exactly one instance with a shared access point – use sparingly, it is global state in disguise.
Structural patterns
- Adapter
Wraps an incompatible interface so it matches what the client expects, without touching existing code.
- Bridge
Splits an abstraction and its implementation into two hierarchies that can evolve independently.
- Composite
Lets clients treat a single element and a whole tree of elements in exactly the same way.
- Decorator
Adds behaviour by wrapping an object instead of multiplying subclasses.
- Facade
One simple entry point in front of a complicated subsystem.
- Flyweight
Saves memory by sharing immutable state between thousands of small objects.
- Proxy
Stands in for the real object and controls access to it: lazy loading, caching, permissions.
Behavioral patterns
- Chain of Responsibility
Passes a request along a chain of handlers until one of them deals with it.
- Command
Turns a request into an object you can queue, log and undo.
- Iterator
Walks through a collection without exposing how it is stored.
- Mediator
Centralises communication so objects stop depending on each other directly.
- Memento
Captures and restores an object's state without breaking its encapsulation.
- Observer
Notifies subscribers whenever the observed object's state changes.
- State
An object's behaviour changes with its internal state, replacing sprawling conditionals.
- Strategy
Interchangeable algorithms in separate classes, picked at runtime.
- Template Method
A base class fixes the skeleton of an algorithm and subclasses fill in selected steps.
- Visitor
Adds new operations to an object structure without modifying its classes.