Software design pattern
lastmod 2026-07-27created 2020-09-2118 edits
In software engineering, a software design pattern is a reusable solution to a commonly occurring problem within a given context in software design. It is not a finished design that can be transformed directly into source or machine code; rather, it is a description or template for how to solve a problem that can be used in many different situations. Design patterns are formalized best practices that programmers can use to solve common problems when designing an application or system.
Gang of Four
Creational Patterns
- Abstract Factory pattern: A pattern that provides an interface for creating families of related objects or families of independent objects without specifying their concrete classes.
- Builder pattern: A pattern that separates the construction process of a Composite object from its representation, so that the same construction process can create different representations.
- Factory Method: A pattern that predefines an interface for creating an object but lets subclasses decide which class to instantiate. Defers instantiation of a class to subclasses.
- Prototype pattern: A pattern that uses a prototypical instance to specify the kind of objects to create, and creates new objects by copying this prototype.
- Singleton pattern: A pattern that ensures a class has only one instance and provides a global point of access to it.
Structural Patterns
- Adapter: A pattern that converts the interface of a class into another interface the user expects, letting classes work together that otherwise couldn't because of incompatible interfaces.
- Bridge: A pattern that decouples an abstraction from its implementation so that the two can vary independently.
- Composite: A pattern that composes objects into tree structures to represent part ? whole hierarchies, letting users treat individual objects and compositions of objects uniformly
- Decorator: A pattern that attaches additional responsibilities to an object depending on the situation and purpose; it can be an alternative to subclassing when extending functionality.
- Facade: A pattern that provides a unified interface to a set of interfaces in a subsystem; it defines a higher-level interface that makes the subsystem easier to use.
- Flyweight: A pattern that uses sharing to support large numbers of small objects efficiently.
- Proxy: A pattern that provides a surrogate or placeholder for another object to control access to it.
Behavioral Patterns
- Chain of responsibility: A pattern that avoids coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chains the receiving objects and passes the request along the chain until an object that handles it is reached.
- Command pattern: A pattern that encapsulates a request as an object, thereby supporting parameterization of users with different requests, queuing or logging of requests, and undoable operations.
- Interpreter pattern: A pattern that, given a language, defines a representation for its grammar along with an interpreter that uses the representation to interpret sentences written in the language.
- Iterator pattern: A pattern that provides a way to access the elements of a collection of objects sequentially without exposing its underlying representation.
- Mediator pattern: A pattern that defines an object that encapsulates how a set of objects interact. It promotes loose coupling by keeping objects from referring to each other directly, and lets developers vary their interaction independently.
- Memento pattern: A pattern that captures and externalizes an object's internal state without violating encapsulation, so that the object can be restored to this state later.
- Observer pattern: A pattern that defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
- State pattern: A pattern that allows an object to alter its behavior when its internal state changes; the object will appear to change its class.
- Strategy pattern: A pattern that defines a family of algorithms, encapsulates each one, and makes them interchangeable. It lets the algorithm vary independently from the users that use it.
- Template method pattern: A pattern that defines only the skeleton of an algorithm in an operation, deferring the concrete processing of each step to subclasses. Lets subclasses redefine the processing of each step of an algorithm without changing the algorithm's structure.
- Visitor pattern: A pattern that represents an operation to be performed on the elements of an object structure. Lets you define a new operation without changing the classes of the elements on which it operates.
Cloud Design Patterns
These design patterns are useful for building reliable, scalable, secure applications in the cloud.
| Pattern | Summary | Category |
| Ambassador | Create helper services that send network requests on behalf of a consumer service or application. | Design and implementation, Operational excellence |
| Anti-Corruption Layer | Implement a facade or adapter layer between a modern application and a legacy system. | Design and implementation, Operational excellence |
| Asynchronous Request-Reply | Decouple backend processing from a frontend host, where backend processing needs to be asynchronous, but the frontend still needs a clear response. | Messaging |
| Backends for Frontends | Create separate backend services to be consumed by specific frontend applications or interfaces. | Design and implementation |
| Bulkhead | Isolate elements of an application into pools so that if one fails, the others will continue to function. | Reliability |
| Cache-Aside | Load data on demand into a cache from a data store | Data management, Performance efficiency |
| Choreography | Let each service decide when and how a business operation is processed, instead of depending on a central orchestrator. | Messaging, Performance efficiency |
| Handle faults that might take a variable amount of time to fix when connecting to a remote service or resource. | Reliability | |
| Claim Check | Split a large message into a claim check and a payload to avoid overwhelming a message bus. | Messaging |
| Compensating Transaction | Undo the work performed by a series of steps, which together define an eventually consistent operation. | Reliability |
| Competing Consumers | Enable multiple concurrent consumers to process messages received on the same messaging channel. | Messaging |
| Compute Resource Consolidation | Consolidate multiple tasks or operations into a single computational unit. | Design and implementation |
| CQRS | Segregate operations that read data from operations that update data by using separate interfaces. | Data management, Design and implementation, Performance efficiency |
| Deployment Stamps | Deploy multiple independent copies of application components, including data stores. | Availability, Performance efficiency |
| Event Sourcing | Use an append-only store to record the full series of events that describe actions taken on data in a domain. | Data management, Performance efficiency |
| External Configuration Store | Move configuration information out of the application deployment package to a centralized location. | Design and implementation, Operational excellence |
| Federated Identity | Delegate authentication to an external identity provider. | Security |
| Gatekeeper | Protect applications and services by using a dedicated host instance that acts as a broker between clients and the application or service, validates and sanitizes requests, and passes requests and data between them. | Security |
| Gateway Aggregation | Use a gateway to aggregate multiple individual requests into a single request. | Design and implementation, Operational excellence |
| Gateway Offloading | Offload shared or specialized service functionality to a gateway proxy. | Design and implementation, Operational excellence |
| Gateway Routing | Route requests to multiple services using a single endpoint. | Design and implementation, Operational excellence |
| Geodes | Deploy backend services into a set of geographical nodes, each of which can service any client request in any region. | Availability, Operational excellence |
| Health Endpoint Monitoring | Implement functional checks in an application that external tools can access through exposed endpoints at regular intervals. | Availability, Operational excellence |
| Index Table | Create indexes over the fields in data stores that are frequently referenced by queries. | Data management, Performance efficiency |
| Leader Election | Coordinate the actions performed by a collection of collaborating task instances in a distributed application by electing one instance as the leader that assumes responsibility for managing the other instances. | Design and implementation, Reliability |
| Materialized View | Generate prepopulated views over the data in one or more data stores when the data isn't ideally formatted for required query operations. | Data management, Operational excellence |
| Pipes and Filters | Break down a task that performs complex processing into a series of separate elements that can be reused. | Design and implementation, Messaging |
| Priority Queue | Prioritize requests sent to services so that requests with a higher priority are received and processed more quickly than those with a lower priority. | Messaging, Performance efficiency |
| Publisher/Subscriber | Enable an application to announce events to multiple interested consumers asynchronously, without coupling the senders to the receivers. | Messaging |
| Queue-Based Load Leveling | Use a queue that acts as a buffer between a task and a service that it invokes, in order to smooth intermittent heavy loads. | Availability, Messaging, Resiliency, Performance efficiency |
| Retry | Enable an application to handle anticipated, temporary failures when it tries to connect to a service or network resource by transparently retrying an operation that's previously failed. | Reliability |
| Scheduler Agent Supervisor | Coordinate a set of actions across a distributed set of services and other remote resources. | Messaging, Reliability |
| Sequential Convoy | Process a set of related messages in a defined order, without blocking processing of other groups of messages. | Messaging |
| Sharding | Divide a data store into a set of horizontal partitions or shards. | Data management, Performance efficiency |
| Sidecar | Deploy components of an application into a separate process or container to provide isolation and encapsulation. | Design and implementation, Operational excellence |
| Static Content Hosting | Deploy static content to a cloud-based storage service that can deliver them directly to the client. | Design and implementation, Data management, Performance efficiency |
| Strangler Fig | Incrementally migrate a legacy system by gradually replacing specific pieces of functionality with new applications and services. | Design and implementation, Operational excellence |
| Throttling | Control the consumption of resources used by an instance of an application, an individual tenant, or an entire service. | Availability, Performance efficiency |
| Valet Key | Use a token or key that provides clients with restricted direct access to a specific resource or service. | Data management, Security |
- Data management
- Data management is the key element of cloud applications and influences most of the quality attributes. Data is typically hosted in different locations and across multiple servers for reasons such as performance, scalability, or availability, and this can present a range of challenges. For example, data consistency must be maintained, and data will typically need to be synchronized across different locations.
- Design and implementation
- Good design encompasses factors such as consistency and coherence in component design and deployment, maintainability to simplify administration and deployment, and reusability to allow components and subsystems to be used in other applications and in other scenarios. Decisions made during the design and implementation phase have a huge impact on the quality and the total cost of ownership of cloud-hosted applications and services.
- Messaging
- The distributed nature of cloud applications requires a messaging infrastructure that connects the components and services, ideally in a loosely coupled manner in order to maximize availability. Asynchronous messaging is widely used and provides many benefits, but also brings challenges such as the ordering of messages, poison message management, and idempotency.
Other software design patterns
- Model View Controller pattern (MVC)
- Model View Presenter (MVP)
- Model View Viewmodel (MVVM)
- Reactor pattern & Proactor pattern: Event handling
- Half-Sync/Half-Async
- Producer–consumer problem
- Sleeping barber problem
- Cigarette smokers problem
- Readers–writers problem
- Dining philosophers problem
- Semaphore
- Entity–component–system (Entity System)
- Monorepo: Managing various modules in a single repository instead of multiple repositories.
- Publish–subscribe pattern
- Feature-Sliced Design (FSD)
Software architecture design
See Software architecture for related content.
Software Design Patterns
| Creational | Abstract factory, Builder, Dependency injection, Factory method, Lazy initialization, Multiton, Object pool, Prototype, RAII, Singleton |
| Structural | Adapter, Bridge, Composite, Decorator, Delegation, Facade, Flyweight, Front controller, Marker interface, Module, Proxy, Twin |
| Behavioral | Blackboard, Chain of responsibility, Command, Interpreter, Iterator, Mediator, Memento, Null object, Observer, Servant, Specification, State, Strategy, Template method, Visitor |
| Functional | Monoid, Functor, Applicative, Monad, Comonad, Free monad, HOF, Currying, Function composition, Closure, Generator |
| Concurrency | Active object, Actor, Balking, Barrier, Binding properties, Coroutine, Compute kernel, Double-checked locking, Event-based asynchronous, Fiber, Futex, Futures and promises, Guarded suspension, Immutable object, Join, Lock, Messaging, Monitor, Nuclear, Proactor, Reactor, Read write lock, Scheduler, STM, Thread pool, Thread-local storage |
| Architectural | ADR, Active record, Broker, Client–server, CBD, DAO, DTO, DDD, ECB, ECS, EDA, Front controller, Identity map, Interceptor, Implicit invocation, Inversion of control, Model 2, MOM, Microservices, MVA, MVC, MVP, MVVM, Monolithic, Multitier, Naked objects, ORB, P2P, Publish–subscribe, PAC, REST, SOA, Service locator, Specification |
| Cloud Distributed | Ambassador, Anti-Corruption Layer, Bulkhead, Cache-Aside, Circuit Breaker, CQRS, Compensating Transaction, Competing Consumers, Compute Resource Consolidation, Event Sourcing, External Configuration Store, Federated Identity, Gatekeeper, Index Table, Leader Election, MapReduce, Materialized View, Pipes, Filters, Priority Queue, Publisher-Subscriber, Queue-Based Load Leveling, Retry, Scheduler Agent Supervisor, Sharding, Sidecar, Strangler, Throttling, Valet Key |
| Other | Business delegate, Composite entity, Intercepting filter, Lazy loading, Mangler, Mock object, Type tunnel, Method chaining |
| Books | Design Patterns, Enterprise Integration Patterns, Code Complete, POSA |
| People | Christopher Alexander, Erich Gamma, Ralph Johnson, John Vlissides, Grady Booch, Kent Beck, Ward Cunningham, Martin Fowler, Robert Martin, Jim Coplien, Douglas Schmidt, Linda Rising |
| Communities | The Hillside Group, The Portland Pattern Repository |
See also
- Design pattern
- Software design
- Software design patterns
- Gang of Four (GoF)
- Algorithms
- Software architecture - Software architecture design.
- Event driven architecture
- System Architecture
- Layered Design - A design approach for preventing circular package references.
Favorite site
- Wikipedia (en) description of software design patterns
- Design Patterns Quick Reference 1
- Refactoring.Guru - Refactoring and Design Patterns - Refactoring.Guru is a resource where you can easily find everything you need to know about refactoring, design patterns, SOLID principles, and other smart programming topics.
References
-
Designpatternscard.pdf ↩