Design patterns every developer should know
Named, reusable solutions to problems that keep reappearing in object-oriented design.
Design patterns are proven, named solutions to recurring design problems. The classic catalog splits into three families: creational patterns control how objects are made, structural patterns compose objects into larger shapes, and behavioral patterns coordinate how objects communicate. They are a shared vocabulary, not a checklist to apply everywhere.
What a pattern is
A design pattern is a general, reusable solution to a problem that recurs across many programs. It is not code you copy but a description of the roles, relationships and responsibilities that solve the problem. The famous Gang of Four catalog named 23 of them and gave developers a shared language for discussing design.
Creational patterns
Creational patterns abstract the process of instantiating objects so the rest of the system does not depend on concrete classes. Singleton guarantees one shared instance, Factory defers which class to create to a subclass or method, and Builder assembles a complex object step by step. Together they decouple what you use from how it is constructed.
Structural patterns
Structural patterns describe how to compose objects and classes into larger structures while keeping them flexible. Adapter makes an incompatible interface usable, Decorator wraps an object to add behavior without subclassing, Facade offers a simple front to a complex subsystem, and Proxy stands in for another object to control access. They are about assembling parts cleanly.
Behavioral patterns
Behavioral patterns concern how objects interact and distribute responsibility. Observer lets many objects react to a subject's changes, Strategy makes an algorithm swappable at runtime, Command turns a request into an object you can queue or undo, and Iterator exposes a sequence without revealing its structure. They organize communication and control flow.
Use them judiciously
Patterns are tools for a purpose, not a scorecard. Introducing a Factory or an Observer where a plain function or a direct call would do adds indirection that makes code harder to read. Reach for a pattern when its specific problem — swapping algorithms, decoupling producers from consumers — actually appears, and prefer the simplest design that works.
Why design patterns exist
As object-oriented software grew in the 1990s, developers kept noticing that the same design problems reappeared across wildly different programs: how do you make sure there is exactly one configuration object, how do you let a piece of UI react to data changing, how do you add behavior to an object without editing its class. Good engineers solved these repeatedly, each in their own way, and the solutions were hard to communicate because they had no names.
Four authors — later nicknamed the Gang of Four — catalogued 23 of these recurring solutions in a 1994 book, and the idea of the *design pattern* was born. A pattern is not an algorithm and not a library; it is a description of a solution's structure — the participating objects, their roles, and how they collaborate — that you adapt to your own context. Its deepest value is as a shared vocabulary: when one developer says "let's make that a Strategy" or "wrap it in a Decorator," an entire design intent is communicated in a couple of words, and that is why patterns are still worth learning even in languages very different from the ones they were first written for.
Creational patterns — controlling how objects are born
Creational patterns tackle a single question: how do objects get made, and how do we keep the rest of the code from depending on the exact classes involved. By hiding the construction details behind an interface, they let you change what gets built without touching the code that uses it.
- Singleton ensures a class has only one instance and gives everyone a global access point to it — used for things like a configuration store or a connection pool where multiple copies would be wrong. (It is also the most abused pattern, because it is really a controlled global variable.)
- Factory Method defines an interface for creating an object but lets subclasses or a dedicated method decide which concrete class to instantiate, so the caller works against an abstraction.
- Builder separates the construction of a complex object from its representation, assembling it step by step. It shines when an object has many optional parts and you want to avoid a constructor with a dozen arguments.
The common thread is decoupling *what you need* from *how it is created*, which keeps calling code stable as the concrete types evolve.
Structural patterns — composing objects into shapes
Structural patterns are about assembling classes and objects into larger structures while keeping those structures flexible and efficient. They answer "how do I fit these pieces together" rather than "how do I make them."
- Adapter wraps an object with an incompatible interface so it can be used where a different interface is expected — the software equivalent of a plug adapter. It is how you bolt a third-party or legacy component onto code that expects a different shape.
- Decorator wraps an object to add responsibilities dynamically, without subclassing. You can stack decorators — a data stream wrapped in compression wrapped in encryption — each adding one behavior.
- Facade provides a single, simplified interface to a complex subsystem, so callers do not have to understand every moving part underneath.
- Proxy provides a stand-in for another object to control access to it — useful for lazy loading, caching, access control, or talking to a remote object as if it were local.
Together they let you build rich structures out of small parts without rigid, brittle inheritance hierarchies.
Behavioral patterns — coordinating who does what
Behavioral patterns focus on communication and the assignment of responsibilities between objects — how control and data flow through a design.
- Observer defines a one-to-many dependency so that when one object (the subject) changes state, all its dependents are notified automatically. It underpins event systems, UI data binding, and publish/subscribe.
- Strategy defines a family of interchangeable algorithms behind a common interface and lets you swap them at runtime. Instead of a sprawling
if/elsechoosing behavior, you inject the strategy you want — a sorting order, a pricing rule, a compression scheme. - Command turns a request into a standalone object carrying everything needed to perform it, which makes it possible to queue requests, log them, or support undo/redo.
- Iterator provides a way to traverse the elements of a collection sequentially without exposing its underlying representation — the pattern behind every
for-eachloop.
These patterns replace tangled, hard-coded control flow with clean, extensible collaborations.
Using patterns well — and knowing when not to
The single most important lesson about design patterns is that they are a means, not an end. A pattern earns its keep by solving a real problem — a swappable algorithm, a decoupled event flow, a simplified subsystem boundary — and it costs you abstraction and indirection in return. When the problem is genuinely present, that trade is a bargain; when it is not, you have added layers that make the code harder to follow for no benefit. Cargo-culting patterns into a codebase is a classic form of over-engineering.
The practical discipline is to let patterns emerge from need rather than imposing them up front. Write the straightforward code first; when you feel a specific pain — a constructor exploding with arguments, a chain of type checks choosing behavior, a class you keep subclassing just to add small variations — reach for the pattern whose intent matches that pain. Learn the whole catalog so you recognize the shapes, but apply it with restraint. A senior developer is marked as much by the patterns they choose *not* to use as by the ones they do, always favoring the simplest design that clearly expresses the intent.
A design pattern is a reusable template for a common problem, not a finished piece of code you paste in.
Creational patterns (Singleton, Factory, Builder) control object creation and hide construction details.
Structural patterns (Adapter, Decorator, Facade, Proxy) compose objects and classes into larger, flexible structures.
Behavioral patterns (Observer, Strategy, Command, Iterator) manage responsibilities and communication between objects.
Patterns are a shared vocabulary — saying "use a Strategy here" conveys an entire design in two words.
Overusing patterns adds needless abstraction; reach for one only when the problem it solves is actually present.
Quick quiz
Which family does the Factory pattern belong to?
What is the main risk of using design patterns?
The SOLID principles
Five object-oriented design rules that keep code flexible instead of fragile.
Clean code principles
Code is read far more often than it is written — clean code optimizes for the reader.
How clean architecture works
Concentric rings of code where every dependency points toward the business rules.
Coding patterns for interviews
Most interview problems are variations on a dozen reusable patterns — learn the patterns, not the problems.