Guide
Why Learn Patterns
What knowing design patterns buys a developer or coding agent: shared vocabulary, faster code reading, better refactoring targets, and knowing when to stop.
The short answer
You will meet these patterns whether you learn them or not. Frameworks, standard libraries and existing codebases are full of them. Learning patterns is mostly about reading code faster and deciding with fewer mistakes, not about writing more abstractions.
Benefits
A shared vocabulary
"Wrap the payment client in an Adapter" says in six words what would otherwise take a paragraph: a new class, a target interface the rest of the app already uses, and translation of calls and errors. In code review, a commit message or an agent's plan, names compress design discussion.
Faster code reading
When you recognize a role, you can predict the rest of the structure. Spotting a class named *Handler with a next field tells you to look for a Chain of Responsibility and find where the chain is assembled. Spotting subscribe/unsubscribe tells you to look for an Observer and check for listener leaks.
Common places you will see patterns without being told:
| You see | Likely pattern |
|---|---|
| Express or Koa middleware, servlet filters | Chain of Responsibility |
addEventListener, RxJS, Node EventEmitter | Observer |
Query builders, StringBuilder, test data builders | Builder |
| Java I/O streams, HTTP client interceptors | Decorator |
ORM lazy-loaded relations, JS Proxy | Proxy |
| Undo stacks in editors | Command and Memento |
| Compiler AST passes | Visitor |
Better refactoring targets
Smells tell you something is wrong. Patterns tell you what "better" can look like. A growing type switch (Switch Statements) has a known destination in Strategy or State. Two incompatible classes doing the same job (Alternative Classes with Different Interfaces) may need an Adapter. Having a destination keeps refactoring from drifting.
Knowing when to stop
Each pattern on this site has a "Do not use it when" section. Learning a pattern properly includes learning its misfits. Developers who know only the solution side apply it everywhere. Developers who know the forces apply it where it pays.
Why it matters more for agents
An AI coding agent generates code quickly, so the cost of over-engineering is paid by the humans who maintain the result. Patterns help an agent in specific ways:
- Recognize existing structure before editing. If a codebase already uses Strategy for pricing rules, add a new strategy; don't add a new
ifinside the context. - Communicate intent. A plan that says "introduce a Facade over the three reporting services" is quick for a human to approve or reject.
- Avoid reinventing. Many requests ("let users undo", "notify subscribers", "support a new storage backend") map onto known structures with known pitfalls.
- Resist pattern inflation. The checklists on each page exist to stop an agent from turning a 20-line function into five classes.
See Using this reference as an agent for the full workflow.
What not to expect
- Patterns do not make a design correct. A wrong abstraction behind a well-named pattern is still wrong.
- Patterns are not a checklist to maximize. Code with zero named patterns can be excellent.
- Patterns are not language-neutral in cost. Some vanish in languages with closures, generics or pattern matching. See History of patterns.
How to learn them efficiently
- Read the intent and the "Do not use it when" section of every pattern first. That gives you recognition and restraint.
- Learn the frequently seen ones in depth: Strategy, Observer, Adapter, Decorator, Factory Method, Builder, Facade.
- Learn the confusable pairs side by side: Strategy vs State, Decorator vs Proxy, Adapter vs Facade, Factory Method vs Abstract Factory (Factory comparison).
- Practice by refactoring toward a pattern from a real smell, not by writing one from scratch.
See also
- What Is a Design PatternA design pattern is a named, reusable solution shape for a recurring design problem. Learn what one contains and how it differs from an algorithm or library.
- Criticism of PatternsThe main arguments against design patterns, including missing language features, misuse, and over-engineering, and how to apply patterns without those failures.
- Choosing a PatternA decision guide that maps concrete code symptoms to the pattern that fixes them, and tells you when plain code beats any pattern.
- How Agents Should Use This ReferenceRules for AI coding agents using this reference: diagnose a named smell, read the exclusions first, apply one technique at a time and verify with tests.
Original writing and examples. Topic coverage follows Refactoring.Guru, which explains this topic with its own illustrations.