Link copied to clipboard!
Design Patterns (GoF 23)
Simple index. Each pattern: small intent. Style: almost mathematical, simple English.
Notation: Object set O, Class set C, Interface set I, Behavior (method) set B.
Creational (make objects)
- Singleton — ensure |instances(P)| = 1.
- Factory Method — choose subclass via f(): C_base → C_concrete.
- Abstract Factory — group creation: F: Family → (Product_1 × ... × Product_n).
- Builder — separate build steps s₁..s_k from final assemble A.
- Prototype — clone: new(o) = copy(o) without class knowledge.
Structural (compose objects)
- Adapter — adapt target interface: g = wrap(f) so sig(g)=Target.
- Bridge — split Abstraction × Implementor to reduce |A×I| coupling.
- Composite — tree T where Leaf and Node share I: uniform op.
- Decorator — add behavior: x' = D(x) preserving interface.
- Facade — map complex subsystem S to simple interface F.
- Flyweight — share intrinsic state: extrinsic passed per use.
- Proxy — control access: p(x) mediates real r(x).
Behavioral (coordinate behavior)
- Chain of Responsibility — handlers h₁→h₂→... stop at first accept.
- Command — encapsulate request: cmd := (execute, undo).
- Interpreter — grammar G → class tree; eval(node) recursively.
- Iterator — expose sequence: next(): O ∪ {Ø}.
- Mediator — central M: reduce edges from O(n²) to O(n).
- Memento — capture state σ; restore(σ).
- Observer — subject S: notify all o ∈ Obs when state Δ.
- State — behavior depends on current q ∈ Q; transition on event.
- Strategy — swap algorithm: context uses a ∈ A via common I.
- Template Method — algorithm skeleton fixed; steps overridden.
- Visitor — add ops: double dispatch visit(Structure, Visitor).
Graph View
Force graph: 3 category nodes (C) and pattern nodes (P). Edge (C,P) if P in C.
Palette: Category=#1d4ed8, Pattern=#0d9488.
next