Developers keep running into the same design problems in object-oriented code, and at some point someone started giving the solutions names. A software design pattern is a reusable design solution for a problem that recurs in a given context, documented in terms of the roles and relationships between classes and objects. Each application implements it again. Nobody copies code out of it.
Teams use patterns to structure object-oriented systems and to talk about designs in a shared vocabulary. The Gang of Four catalog (Addison-Wesley, 1994) holds 23 of them, but the idea is older. Kent Beck and Ward Cunningham adapted Christopher Alexander’s architectural patterns to Smalltalk in a technical report dated 17 September 1987.
What Is a Software Design Pattern?

It’s a template for structuring classes and objects, and it isn’t finished code. The Gang of Four (Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides) say so directly in their 1994 book, because a developer can’t paste a pattern into a project. What the pattern gives you is roles and relationships, and every application has to implement them again.
Useful for communication, useless as a copy-and-paste snippet.
| Concept | Scale | What it prescribes | Example |
|---|---|---|---|
| Design pattern | Classes and objects in a subsystem | Roles, relationships and trade-offs for a recurring problem | Observer |
| Algorithm | One computation | Finite steps for a specific problem | Quicksort |
| Architectural pattern | Whole system | Component layout and interaction | Model-View-Controller |
| Idiom | One programming language | A language-level implementation technique | RAII in C++ |
| Framework | One application domain | Reusable code that controls program flow | Spring Framework |
Design Pattern vs Algorithm
Algorithms are a finite sequence of instructions for a specific problem, so the steps are fixed. A design pattern describes the solution at a higher level and leaves the exact steps open, which is why the code for the same pattern can differ between two programs (Refactoring.Guru).
The two combine in practice. Strategy lets a program swap one sorting algorithm for another at runtime.
Design Pattern vs Architectural Pattern, Idiom and Framework

An architectural pattern describes the fundamental structure of a whole system and is often assembled from design patterns. That puts it closer to software architecture than to class-level design, and the Pattern-Oriented Software Architecture series (Buschmann et al., Wiley, 1996) is the standard catalog.
Model-View-Controller shows how the two levels connect. In the Gang of Four’s breakdown, the view observes the model (Observer) and the controller acts as a strategy for user input (Strategy). Nested views also form a Composite.
Idioms are tied to one language. Kent Beck’s Implementation Patterns (2007) draws the line here: design patterns describe relationships between classes, while implementation patterns usually stay inside a single class.
Frameworks are the trickiest to separate from patterns, and the Gang of Four book spells out how. Patterns are more abstract, since only examples of a pattern can be written as code, and they’re smaller, because a framework contains several of them and never the reverse. They are also less specialized, since a framework always targets an application domain.
A framework also holds control of the program flow and calls the developer’s code, not the other way around.
Elements of a Design Pattern: Name, Problem, Solution and Consequences

Every pattern in the Gang of Four book comes with a name, a problem, a solution and consequences. The name works as a handle for the design problem, its solution and its consequences, all in a word or two. The problem tells you when to apply the pattern, including its context and often a list of preconditions. Then there’s the solution, meaning the design elements and their relationships, responsibilities and collaborations. Consequences come last, and they cover the results and trade-offs of applying it.
The solution stays abstract on purpose. A developer fits the template to the surrounding codebase instead of copying code.
The authors point out that consequences usually go unstated when designers describe a decision. They still decide whether a design pays off, which is why the format names them.
The full catalog entry in the 1994 book runs to 13 sections, among them Intent, Motivation, Applicability, Structure, Participants, Collaborations and Known Uses. Structure is drawn with class diagrams and interaction diagrams.
How the Four Elements Differ From Alexander’s Original Format
Alexander defined a pattern as a three-part rule relating a context, a problem and a solution (quoted in Grimm, Modernes C++, 2022).
Beck and Cunningham’s 1987 report describes written patterns the same way: a statement of the problem, the circumstances behind it, and a solution that works in those circumstances. The Gang of Four format adds consequences as a named element.
No single format won. Brad Appleton’s 1998 pattern handout lists name, context, problem, forces, solution and resulting context, and Wikipedia notes that pattern authors use a variety of formats.
Origin of Design Patterns: From Christopher Alexander to the Gang of Four
Design patterns started in architecture, not software. Christopher Alexander supplied the idea in 1977. Ten years later Kent Beck and Ward Cunningham carried it into programming, and the Gang of Four turned it into a catalog in 1994.
- 1977 brought A Pattern Language, with 253 patterns (Oxford University Press)
- On 17 September 1987 came Beck and Cunningham’s report CR-87-43, with five patterns for Smalltalk windows
- October 1994 saw Design Patterns: Elements of Reusable Object-Oriented Software, with 23 patterns (Addison-Wesley)
- The first Pattern Languages of Programming conference followed in 1994, and the Portland Pattern Repository in 1995 (Wikipedia)
Alexander and A Pattern Language
Alexander wrote the book with Sara Ishikawa, Murray Silverstein, Max Jacobson, Ingrid Fiksdahl-King and Shlomo Angel at the Center for Environmental Structure in Berkeley. Each pattern states a problem, discusses it and gives a solution.
The book is built as a network. Patterns point to other patterns, which is why the authors call the whole set a language and not a checklist.
Beck and Cunningham at OOPSLA 1987
Technical Report CR-87-43 came from Beck (Apple Computer) and Cunningham (Tektronix) for the OOPSLA-87 workshop on Specification and Design for Object-Oriented Programming.
It proposed five patterns for Smalltalk window interfaces: Window Per Task, Few Panes Per Window, Standard Panes, Short Menus, and Nouns and Verbs.
The authors report that a team of application specialists, with no detailed knowledge of Smalltalk’s interface mechanisms, wrote reasonable interface specifications after one day of practice. They expected the finished language to hold 100 to 150 patterns.
The Gang of Four Catalog

Gamma and Helm met at a birds-of-a-feather session at OOPSLA 1990 titled “Towards an Architecture Handbook”. Johnson and Vlissides joined later.
The book reached the public at OOPSLA 1994, with examples in C++ and Smalltalk.
Sources disagree on the exact release day. Wikipedia gives 21 October 1994, and Pearson’s catalog lists 31 October 1994. The 1995 copyright date explains why citations alternate between the two years.
The community built around the book quickly. The first Pattern Languages of Programming conference ran in 1994, and the Portland Pattern Repository followed in 1995 for documenting patterns.
In 2005 the ACM SIGPLAN gave the four authors its Programming Languages Achievement Award for the book’s effect on programming practice and language design.
What Are the Types of Design Patterns?

The Gang of Four catalog groups its 23 patterns by purpose, and the table shows how they split between creational, structural and behavioral.
| Category | Count | Purpose | Patterns |
|---|---|---|---|
| Creational | 5 | Create objects without instantiating them directly | Abstract Factory, Builder, Factory Method, Prototype, Singleton |
| Structural | 7 | Compose classes and objects into larger structures | Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy |
| Behavioral | 11 | Govern communication and responsibility between objects | Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor |
Creational Patterns
Creational patterns create objects so that the program does not instantiate them directly, which gives it flexibility in choosing what to build for a given case.
Factory Method defines an interface for creating an object and lets subclasses pick the class. Abstract Factory groups factories that share a common theme, and Builder separates the construction of a complex object from its representation.
Prototype creates objects by cloning an existing one, and Singleton restricts a class to a single instance.
Structural Patterns
Structural patterns assemble classes and objects into larger structures while keeping those structures flexible.
Facade puts one simplified interface in front of a large body of code. Adapter does a different job: it wraps an existing class so that incompatible interfaces can work together.
Bridge decouples an abstraction from its implementation, and Composite lets a tree of objects be handled as one. Proxy stands in for another object to control access.
Behavioral Patterns
Behavioral patterns are the largest group, 11 of the 23, and most of them govern how objects communicate.
Chain of Responsibility passes a request along a chain of handlers. Command turns an action and its parameters into an object, which supports queuing, logging and undoable operations.
Strategy and Template Method both vary an algorithm, but Strategy works at object level through composition and delegation, while Template Method works at class level through inheritance (Refactoring.Guru).
Patterns Beyond the Original 23
The count depends on who keeps the catalog. As of October 2026, the Refactoring.Guru catalog lists 22 patterns (5 creational, 7 structural, 10 behavioral) and leaves out Interpreter, which implements a specialized language.
The authors saw gaps too. In a 2009 InformIT interview, Gamma shared notes from a 2005 session in which the authors concluded they would recategorize some patterns and add extension object, type object, null object and dependency injection.
The last of those, dependency injection, has a class accept the objects it needs from an injector instead of creating them itself.
Other catalogs cover other levels. Pattern-Oriented Software Architecture, Volume 2 (Schmidt, Stal, Rohnert and Buschmann, Wiley, 2000) documents patterns for concurrent and networked objects, such as Active Object and Reactor. Patterns of Enterprise Application Architecture (Martin Fowler, Addison-Wesley, 2002) catalogs patterns for enterprise applications.
Design Pattern Examples: Observer, Factory Method, Strategy and Decorator

Observer: Notifying Dependents of a Change
Say a store has customers waiting on a product. Customers who check daily waste trips, and a store that emails everyone annoys the ones who do not care (the scenario Refactoring.Guru uses for the pattern).
Observer fixes this with a subscription list. The publisher holds its subscribers behind one shared interface with an update method, and calls each of them when its state changes.
The Java version has a history. As of the Java SE 21 API documentation, java.util.Observable and Observer have been deprecated since Java 9. Oracle cites a limited event model and an unspecified notification order, and says state changes do not map one-for-one to notifications.
Refactoring.Guru lists the same weakness among the pattern’s costs, since subscribers are notified in no guaranteed order. Oracle points developers to the java.beans package and the java.util.concurrent structures instead, and mentions the Flow API as well.
Factory Method: Deferring the Choice of Class
Say a logistics app is built around a Truck class. Adding Ship means editing code coupled to Truck across the application and piling up conditionals (Refactoring.Guru’s example).
Replace the direct constructor calls with a factory method and that mess goes away. A RoadLogistics creator returns trucks, a SeaLogistics creator returns ships, and client code sees only a shared Transport interface.
There’s a catch. Subclasses can return different products only when those products share a base class or interface, and every new product type adds a creator subclass.
Strategy: Swapping a Rule at Call Time
Java’s Comparator is the standard case.
A Comparator encapsulates an ordering rule. Passing one to Collections.sort lets the caller choose the order while the sorting routine stays fixed, as Oracle’s Java Collections tutorial demonstrates. Sort employees by seniority with one Comparator, then sort the same list by name with another.
Languages with functional types shrink this further, because a plain function can stand in for the strategy class. Refactoring.Guru makes the same remark about Observer subscribers.
Decorator: Layering Behavior Onto an Object
The JDK’s java.io package is built this way. A FilterInputStream wraps another input stream and passes requests through, while subclasses such as BufferedInputStream, DataInputStream, CipherInputStream, DeflaterInputStream and DigestInputStream add behavior (Java SE 21 API documentation).
The problem it avoids shows up in a notification library with email, SMS, Facebook and Slack subclasses. Supporting every combination of channels needs a new subclass for each one, so wrappers stack instead.
You can add or remove behavior at runtime and combine several behaviors by stacking wrappers, with no new subclass per combination. The costs are real though. Pulling one wrapper out of the middle of a stack is hard, behavior can depend on the order of the wrappers, and the initial layer configuration looks ugly.
Benefits of Using Design Patterns in a Codebase
Design patterns help a team talk to each other, and they make later changes less painful.
Shared Vocabulary
Erich Gamma said that learning the iPhone SDK felt familiar quickly because he already knew the patterns it used.
Ralph Johnson makes a related point in the same 2009 InformIT interview. Patterns are common in reusable software, so programmers who never build a framework still gain from knowing them, and he suggested the book might now aim at people who use patterns chosen by others.
Looser Coupling
The first principle is to program to an interface. Clients stay unaware of the classes behind an object and know only the abstract interface.
The second is to favor composition over inheritance. The authors call composition black-box reuse because no internals of the composed object are visible, and they warn that inheritance exposes a subclass to its parent’s implementation.
Both principles come from the first chapter of the Gang of Four book (1995). The authors call looser coupling desirable for maintainability.
Easier Change and Refactoring
Gamma added a phrase he would put in the book today: evolving reusable object-oriented software is the hardest part. Factories, adapters and facades, he said, help when a reusable library has to change.
Richard Helm describes design for change as the goal of most developers. When the design needs to move, patterns give the code refactoring a target to aim at.
What Studies Show
Classes that take part in design patterns show lower smell-proneness and smell frequency than classes outside them, according to Alfadel, Aljasser and Alshayeb (PLOS ONE, 2020), who studied ten small to medium open-source Java systems.
Some patterns still co-occurred with certain smells in some cases. The benefit holds on average, not in every class.
When Design Patterns Stop Helping

A pattern stops helping when the language already solves the problem or the problem never recurs. It also stops when its indirection costs more than the flexibility it buys.
Language Features That Replace a Pattern
Peter Norvig’s slides found that 16 of the 23 Gang of Four patterns are invisible or simpler in Lisp or Dylan. He first presented them on 5 May 1996 and put them online on 17 March 1998, which is why sources cite both years.
Hannemann and Kiczales (OOPSLA, 2002) came at it from the other side. AspectJ implementations of the same patterns improved modularity in 17 of 23 cases.
JUnit shows the effect in a real project. According to Gamma, JUnit 3 used Composite, Template Method and Command, and JUnit 4 replaced them with annotations (introduced in J2SE 5.0) and a small test runner.
Paul Graham (2002) treats visible patterns in a program as a sign of trouble, evidence of abstractions that are not powerful enough. Johnson sees it differently. He says the Gang of Four patterns target languages between C++ and Smalltalk, and that other languages have a different set of patterns, not none.
The sources disagree on the diagnosis, not on the effect. The same pattern can vanish in one language and stay in another.
Why Singleton Draws the Most Criticism
The criticism comes from inside the catalog.
Asked how the authors would revise the book, Gamma said he favored dropping Singleton because its use is almost always a design smell.
Over-Engineering and Added Indirection
Inappropriate use of patterns can increase complexity without need (Steve McConnell, Code Complete, Microsoft Press, 2004). The Gang of Four authors warn that dynamic, highly parameterized software is harder to understand and build than static software.
A pattern also has to be written again in every application, which some authors see as a step back from component reuse. Meyer and Arnout (2006) turned two-thirds of the patterns they attempted into reusable components, fully or in part.
A decade-long systematic literature review (Almadi, Hooshyar and Ahmad, Sustainability, 2021) identified 28 bad smells in Gang of Four patterns, grouped as code smells and grime symptoms. The authors tie them to higher maintenance costs and energy consumption.
How to Decide Whether a Design Pattern Fits

Use a pattern when the problem actually recurs and the language doesn’t already cover it. Then check that the pattern’s consequences fit the change you expect.
- State what varies: the class created, the rule applied, or the objects notified
- Check the language and framework for a built-in answer
- Read the pattern’s consequences, not only its structure
- Pick the smallest pattern that fits and let it grow if needed
- Name the pattern in comments and in the design document
Step 2 matters more than it looks. Wikipedia notes that patterns implying mutable state may suit functional languages poorly, and the Observable deprecation above shows a platform retiring its own implementation.
For step 4, Refactoring.Guru observes that many designs start with Factory Method and evolve toward Abstract Factory, Prototype or Builder. Those are more flexible and more complicated, so the move should wait for a reason.
For step 5, Prechelt, Unger-Lamprecht, Philippsen and Tichy (IEEE Transactions on Software Engineering, 2002) ran two controlled experiments on maintenance tasks. Pattern-relevant tasks finished faster or with fewer errors when explicit pattern comments were present.
Record the choice in the design document as well, so the pattern is named wherever maintainers look first.
What Maintenance Experiments Say About Simpler Alternatives
Prechelt and colleagues (IEEE Transactions on Software Engineering, 2001) compared pattern designs with simpler alternatives across nine maintenance tasks, using professional engineers. In most tasks the pattern delivered its extra flexibility at no cost in maintenance time, or cut the time.
In a few tasks the simpler alternative won, being less error-prone or faster to change. One surprise was a negative effect from an Observer application that looked well justified.
The authors concluded that, unless there is a clear reason to prefer the simpler solution, taking the pattern’s flexibility is probably wise because unexpected requirements often appear.
That cuts against the common advice to skip any pattern whose flexibility is not needed today. The limit is scale: four small programs and nine tasks, with open questions the authors list themselves.
Software Design Pattern FAQ
What is an anti-pattern?
Andrew Koenig coined the term for a common solution to a recurring problem that produces clearly negative consequences, and William Brown and colleagues catalogued examples in AntiPatterns (Wiley, 1998).
Ralph Johnson prefers the term code smell, because such problems are not always mistakes.
Are design patterns the same as SOLID principles?
No. A principle is a general rule, and a design pattern is a concrete solution to a recurring problem.
The two work together. Refactoring.Guru credits Factory Method with supporting the Single Responsibility and Open/Closed principles, two of the five SOLID principles that Robert C. Martin popularized.
Do design patterns exist outside object-oriented class design?
Yes. Wikipedia lists patterns codified for user interface design, information visualization, secure design, web design and business model design.
The annual Pattern Languages of Programming conference proceedings hold many domain-specific patterns of this kind.
Which books teach design patterns?
Start with the Gang of Four book, Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley, 1994). It is the reference catalog, with examples in C++ and Smalltalk.
Head First Design Patterns (O’Reilly, 2004) is a widely used teaching book, and the free Refactoring.Guru catalog adds examples in Java, Python and other languages.
Can several design patterns be used together?
Yes, and they often form sequences. Rainer Grimm (Modernes C++, 2022) describes walking a tree and running operations on its leaf nodes.
Iterator moves through the tree and Composite lets nodes with and without children behave alike. Visitor adds the operations.
Which Design Pattern to Learn First

Strategy comes first, because it replaces a branching rule with one interface and a few small classes. Erich Gamma’s 2005 revision notes place it in a proposed Core group of eight patterns, set apart from the less frequently used ones.
Start where a method branches on a type code or a pricing rule. Refactoring.Guru’s catalog names the move Replace Type Code with State/Strategy.
After Strategy, go to Observer for dependent updates and then Decorator for stacked behavior. The order follows scope. A rule is local. Observer adds runtime wiring between objects, and Decorator brings ordering concerns on top of that.
Check the language before writing the class. Norvig’s 16 of 23 and Hannemann and Kiczales’ 17 of 23 must overlap on at least 10 patterns, so a built-in feature often covers the job.
Each pattern costs an interface and a layer of indirection. This position was verified on 30 October 2026 and changes if the team’s language gains a feature that replaces the class.
Once the first pattern is in place, the software development principles behind it show when a second one earns its place.
- Claude Code PyCharm Setup: Using the Agent Inside JetBrains - November 15, 2026
- Notepad++ for Mac: Does It Exist and What to Use Instead - November 13, 2026
- What Communications Teams Should Ask Before Commissioning a Mobile App - November 12, 2026



