A to Z
Glossary
Every concept in this sheet, plus the smaller terms it uses. Select a concept to open its card.
A
- Abstract Factory
- Intent: an interface for creating whole families of related objects, with one concrete factory per family.
- Adapter
- Intent: convert the interface of an existing class into the one your code expects.
B
- Bridge
- Intent: split an abstraction from its implementation so the two can vary independently.
- Builder
- Intent: construct a complex object step by step, separating how it is assembled from what it ends up as.
C
- Chain of Responsibility
- Intent: pass a request along a chain of handlers until one handles it or the chain ends.
- Command
- Intent: turn a request into an object with everything needed to perform it, and often to undo it.
- Common anti-patterns
- Recurring bad shapes: the god object that knows everything, spaghetti code with tangled control flow, copy-paste programming, and magic numbers.
- Composite
- Intent: compose objects into trees and treat single objects and groups the same way.
- Composition over inheritance
- Build behaviour by holding other objects and delegating to them, rather than by deep subclass chains.
- Creational, structural, behavioural
- Creational patterns control how objects are made (5).
D
- Decorator
- Intent: add behaviour to an object by wrapping it in another object with the same interface.
- Dependency injection
- An object receives its collaborators from outside, usually through its constructor, instead of creating them itself.
- Dependency Inversion Principle
- High-level policy should depend on abstractions, and low-level details should implement them; neither depends directly on the other.
- Design pattern
- A named, reusable solution to a design problem that keeps recurring in object-oriented code.
- DRY
- Every piece of knowledge should have one authoritative place in the code.
F
- Facade
- Intent: one simple entry point in front of a complicated subsystem.
- Factory Method
- Intent: let a method decide which class to instantiate, so callers ask for "a transport" without naming the class.
- Flyweight
- Intent: share the common, unchanging part of many similar objects instead of storing it in each one.
H
- High cohesion, low coupling
- Cohesion: things inside a module belong together.
I
- Interface Segregation Principle
- Many small, focused interfaces beat one large one; no class should be forced to implement methods it does not use.
- Interpreter
- Intent: represent the grammar of a small language as classes and evaluate sentences by walking the tree.
- Iterator
- Intent: walk through a collection one item at a time without exposing how it is stored.
K
- KISS and YAGNI
- Prefer the simplest design that works (KISS), and do not build for requirements you do not have yet (YAGNI).
L
- Law of Demeter
- A method should talk only to its own fields, its parameters and objects it creates, not reach through chains like
order.customer.address.city. - Liskov Substitution Principle
- Any subtype must be usable wherever its base type is expected, without surprising the caller.
M
- Mediator
- Intent: objects talk through one mediator instead of referring to each other directly.
- Memento
- Intent: capture an object's internal state as a snapshot so it can be restored later, without exposing its internals.
O
- Observer
- Intent: when one object changes, all objects subscribed to it are notified automatically.
- Open/Closed Principle
- Code should be open for extension but closed for modification: add behaviour by adding new code, not by editing working code.
P
- Patterns and first-class functions
- In languages with first-class functions, Strategy, Command and Template Method often shrink to passing a function, and Iterator becomes a generator.
- Patterns you already use
- Express and Koa middleware is Chain of Responsibility, DOM events are Observer, Java I/O streams are Decorators, Spring beans default to singletons, and React context is a form of dependency injection.
- Problem to pattern map
- A quick lookup from symptom to candidate pattern.
- Program to an interface
- Write code against what an object can do (an interface or abstract type), not which concrete class it is.
- Prototype
- Intent: create new objects by copying an existing, configured instance instead of building from scratch.
- Proxy
- Intent: a stand-in object with the same interface that controls access to the real one.
R
- Reading pattern diagrams
- Pattern books draw UML class diagrams: a box per class, a hollow triangle arrow for "implements or extends", a plain arrow for "uses", and a diamond for "holds or owns".
- Refactoring towards a pattern
- Start with simple code and introduce a pattern when duplication or a growing conditional shows the need, in small tested steps.
S
- Single Responsibility Principle
- A class or module should have one reason to change: it answers to one actor or concern.
- Singleton
- Intent: ensure a class has exactly one instance and give global access to it.
- State
- Intent: an object changes its behaviour when its internal state changes, as if it changed class.
- Strategy
- Intent: define a family of algorithms behind one interface and choose one at run time.
T
- Telling similar patterns apart
- Adapter changes an interface; Facade simplifies a subsystem.
- Template Method
- Intent: a base class fixes the steps of an algorithm and lets subclasses fill in some of them.
V
- Visitor
- Intent: add new operations to a fixed set of classes without changing them, by moving each operation into a visitor object.
W
- When not to use a pattern
- A pattern adds classes and indirection.