What Design Patterns Are
In a Shelfwise design meeting, one developer spends five minutes describing "an object that holds a list of other objects and calls each of them when something happens, without knowing what they are". Another says: "So, an Observer?" Everyone nods. That one word carried the whole design. That is the first gift of design patterns: a shared vocabulary for solutions that keep coming back.
The rule
A pattern is a named solution shape for a problem that keeps recurring.
A design pattern is not a library and not code to paste. It is a description of a problem that shows up again and again, plus the shape of a solution that has worked many times. You adapt the shape to your own code.
Each pattern is usually written up with:
- a name (Strategy, Observer, Decorator),
- the problem it solves and when it applies,
- the structure of the solution (which roles, how they connect),
- the consequences: what you gain and what it costs.
The best-known catalogue comes from a 1994 book by four authors, nicknamed the Gang of Four (GoF). It describes 23 object-oriented patterns in three families:
- Creational: how objects get made. Factory Method, Builder, Singleton.
- Structural: how objects are put together. Adapter, Decorator, Composite.
- Behavioural: how objects share work and talk. Strategy, Observer, Command.
A later series, Pattern-Oriented Software Architecture (PoSA), catalogues larger-scale patterns such as layers, pipes and filters, and brokers. Those shape whole systems rather than a few classes, and belong to the architecture stage of your learning.
Notice how much of the previous section reappears. Most patterns are the design principles applied to a specific problem: encapsulate what varies, program against abstractions, prefer composition.
The shortcut
Before reaching for a pattern, name the problem in one sentence. Then ask which family it belongs to: making objects, assembling them, or coordinating them. That narrows 23 patterns down to a handful.
"Pick the right payment gateway for each country"
It is about which object to create. Creational: look at Factory Method.
The trap is pattern-first design: adding a Factory, a Singleton and an Observer because you just learned them. Each pattern adds indirection, which only pays off when its problem is actually present. Start simple, and refactor toward a pattern when the code starts showing the problem.
Drills
Answer fast — trust the rule.
What is a design pattern?
Which Gang of Four family does Factory Method belong to?
"Wrap an object to add behaviour while keeping its interface." Which family is this?
A new developer wants to add four patterns to Shelfwise before writing any features. What is the best advice?
Remember
- A pattern is a named solution shape for a problem that keeps recurring.
- Name the problem, then its family: making, assembling or coordinating objects.
- Trap: pattern-first design; let the problem arrive before the pattern does.
