How objects talk, delegate, and change behavior over time. The biggest bucket, twelve patterns, because there’s more than one shape for objects to communicate in: chains, commands, states, strategies, and a handful of less common ones you’ll still recognize the moment you’ve seen them once.
- Chain of Responsibility Passes a request through a sequence of handlers until one of them takes it, without any handler knowing about the others.
- Command Wraps an operation as an object, so an invoker can trigger, queue, or undo it without ever knowing the receiver.
- Interpreter Represents each grammar rule as its own class and evaluates an expression by walking the resulting tree.
- Iterator Lets a caller walk a collection without touching its internal storage, and supports multiple independent traversals at once.
- Mediator Routes many-to-many communication between components through one coordinator instead of a web of direct references.
- Memento Snapshots an object’s state for undo/redo without exposing its internals to whatever’s storing the history.
- Null Object Replaces an optional, absent collaborator with a real do-nothing object, killing null checks at every call site.
- Observer Lets a publisher notify an arbitrary, changing set of subscribers without hardcoding who’s listening.
- State Moves per-state behavior into its own class per state, so an entity’s methods stop branching on which stage it’s in.
- Strategy Swaps an entire algorithm at runtime behind one interface, instead of branching on which one to run.
- Template Method Locks a fixed algorithm skeleton in a final method, letting subclasses only override the steps that actually vary.
- Visitor Adds new operations over a fixed set of element types from the outside, without touching the elements themselves.
Comments