Software Design Patterns: 23 GoF Patterns and Practical Examples


Software design patterns are reusable approaches to recurring problems in software design. They describe a structure for organizing responsibilities and interactions between components, rather than providing a finished implementation that can be copied into every project. A pattern gives developers a shared way to reason about a problem: what varies, which component should own a responsibility, how objects collaborate and where a boundary can reduce unnecessary coupling.
The best-known catalogue of object-oriented patterns was popularized by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides in Design Patterns: Elements of Reusable Object-Oriented Software. Often called the Gang of Four, or GoF, the authors grouped 23 patterns into creational, structural and behavioral categories. Those patterns remain useful, but modern software also draws on architectural patterns, functional programming techniques, dependency injection, event-driven design and language-specific idioms.
Patterns are not rules that every application must follow. They are tools for making design decisions. A Strategy pattern can make a changing pricing rule easier to test. An Adapter can isolate an external payment provider's API. An Observer can decouple an event producer from interested consumers. Yet each abstraction introduces concepts that someone must understand and maintain. A few clear functions can be better than a hierarchy of classes when the problem is simple.
This guide explains the major design patterns, when they are useful, how they fit together and how to apply them in real applications. Python examples illustrate several patterns, but the underlying ideas apply to Java, C#, JavaScript, TypeScript, Go, Kotlin, PHP and other languages. The goal is not to memorize pattern names. It is to recognize design pressure, choose an appropriate response and keep the resulting code understandable.
As applications grow, code often becomes difficult to change for reasons that are not obvious in a single function. A component may know too much about another component's implementation. Several classes may duplicate the same decision logic. A new payment provider may require edits throughout the codebase. A notification feature may force the order-processing module to import email, SMS and analytics libraries. A stateful workflow may become a long chain of conditional statements.
These are design problems. They often appear as:
Design patterns help by giving responsibilities clearer homes and defining how components collaborate. They can make variation explicit, isolate external systems, encapsulate algorithms and provide consistent interfaces. They do not automatically make software scalable, secure or fast. Those outcomes still depend on sound architecture, suitable infrastructure, careful implementation and testing.
A useful way to approach a pattern is to ask four questions:
If those questions do not have clear answers, the pattern may be unnecessary.
Patterns work best when they support sound design principles. Understanding these principles is more valuable than memorizing class diagrams.
Identify behaviour that varies independently and isolate it behind a stable interface. If a checkout system supports several shipping calculations, keep each calculation separate from the order workflow. New shipping rules can then be added without rewriting the entire checkout process.
Encapsulation is not simply making fields private. It is protecting a component from decisions that should belong somewhere else. A payment service should not need to know how an email provider formats messages. A domain model should not need to know how an HTTP request is serialized.
High-level business logic should depend on stable contracts rather than concrete infrastructure details. An application service might depend on a payment gateway interface, while a production adapter implements that interface using a third-party provider. A test can supply a fake implementation without making a network request.
Abstractions are valuable when they represent a real boundary or variation. Creating an interface for every class, even when there is only one stable implementation and no meaningful boundary, can make code harder to navigate.
Inheritance can express a genuine subtype relationship, but deep class hierarchies often become rigid. A subclass inherits implementation decisions that may not fit its needs, and changes to a base class can affect many descendants.
Composition builds behaviour by connecting smaller objects or functions. A report generator might combine a formatter, a data source and a delivery mechanism. Each part can be replaced or tested independently. The Decorator, Strategy and Bridge patterns all use composition to achieve flexibility.
A module should have a focused reason to change. This does not mean every class should contain one method. It means related behaviour should be grouped around a coherent responsibility.
For example, a customer notification component should decide how notifications are prepared and delivered. It should not also own order pricing, database migrations and user authentication. Separating unrelated responsibilities makes changes more local and reduces accidental coupling.
A component should not be forced to implement operations it does not need. Small, purpose-specific interfaces are easier to understand and replace than broad interfaces that expose dozens of unrelated methods.
The Dependency Inversion Principle encourages high-level policy to avoid depending directly on low-level details. Both should depend on abstractions that describe the relationship. This is especially useful when business logic interacts with databases, message brokers, payment providers or cloud services.
For a deeper treatment of how these principles influence system structure, see the guide to software architecture and system design and the article on mastering backend architecture.
The classic 23 patterns are grouped according to the design problem they address.
| Category | Main concern | Typical examples |
|---|---|---|
| Creational | How objects are created and configured | Factory Method, Abstract Factory, Builder, Prototype, Singleton |
| Structural | How objects and classes are composed | Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy |
| Behavioral | How responsibilities and communication are organized | Strategy, Observer, Command, State, Iterator and others |
The categories are useful for learning, but they are not mutually exclusive in real systems. A Factory may create a family of objects that collaborate through Strategy interfaces. A Decorator may wrap a Proxy. An event-driven workflow may use Observer-like relationships and Command objects.
Creational patterns separate object creation from the code that uses the resulting objects. They are useful when construction involves configuration, selection, validation, resource management or multiple related implementations.
The Singleton pattern restricts a class to one shared instance and provides a common access point to it. It is sometimes used for application configuration, a registry or a process-wide resource manager.
A Singleton can be appropriate when a resource genuinely has one process-wide owner and its lifecycle is controlled. However, it is easy to overuse. Global mutable state makes tests order-dependent, hides dependencies and can cause concurrency problems. In a web application with multiple worker processes, a Singleton is generally one instance per process, not one instance across the entire deployment.
In Python, imported modules are cached, so a module that exposes carefully managed configuration or a resource factory can often provide the needed shared behaviour without a custom Singleton metaclass. Dependency injection is usually preferable when a component needs a shared service: create it at the application composition root and pass it to the components that require it.
Use Singleton only when uniqueness is an actual domain or lifecycle requirement. Do not use it merely to avoid passing dependencies.
Factory Method defines a creation interface while allowing a concrete creator or subclass to decide which implementation to return. It is useful when a caller should request a capability without knowing the concrete class that provides it.
Imagine a document-processing application that supports PDF, CSV and JSON exports. The export workflow should not contain construction details for every exporter. A factory can select the appropriate implementation based on a validated format, while the rest of the application works with a common exporter contract.
Factory Method is particularly useful when object creation contains business rules, validation or configuration. For a small fixed set of functions, a dictionary of callables may be simpler than a class hierarchy.
Abstract Factory creates families of related objects without exposing their concrete classes. It is useful when several products must be compatible with one another.
A user-interface toolkit might provide a family of controls for different visual themes. A cloud integration layer might provide storage, queue and identity adapters for a selected provider. The application requests a compatible family from one factory rather than mixing components from unrelated providers.
The pattern is justified when the application genuinely needs interchangeable families. If only one family exists and no variation is expected, an abstract factory can be unnecessary indirection.
Builder separates the construction of a complex object from its final representation. It is useful when an object has many optional settings, validation rules or construction steps.
A report builder could accept a date range, data source, output format and privacy options before producing a validated report. The caller can assemble the configuration in a readable sequence without passing a long list of positional arguments.
Builders are also useful when an object must not be used until several invariants have been satisfied. In languages with immutable data structures, a builder can collect values and produce an immutable result at the end.
Do not introduce a Builder for every object with two or three fields. A constructor, named arguments or a small configuration object may already be clear.
Prototype creates new objects by copying an existing configured instance. It is useful when setup is expensive or when many objects share a common baseline configuration.
A document editor might duplicate a template with predefined styles. A simulation system might clone an initial state before exploring several possible outcomes. Python provides shallow and deep copying through the copy module, but copying must be considered carefully when objects contain open files, sockets, database sessions or other resources that should not be duplicated.
A shallow copy duplicates the outer object while retaining references to nested objects. A deep copy recursively copies supported nested values. Neither operation automatically defines correct domain semantics. Explicit clone methods are often safer when the object has complex ownership rules.
Structural patterns describe how components are connected. They help organize dependencies, compose behaviour and present simpler interfaces around complex implementations.
Adapter converts one interface into another interface that a client already understands. It is especially useful when integrating external services, legacy systems or libraries with incompatible APIs.
For example, an application may define a payment gateway contract with an authorize and refund operation. Separate adapters can translate those operations into the request formats required by different payment providers. The checkout logic remains independent of each provider's SDK.
An Adapter should translate between contracts, not become a place for unrelated business rules. Keep provider-specific authentication, request mapping, response normalization and error translation inside the adapter boundary.
Bridge separates an abstraction from its implementation so that both can vary independently. It is useful when two dimensions of variation would otherwise create a large inheritance hierarchy.
Consider a notification system that supports several notification types and several delivery channels. Without a Bridge, developers might create classes for every combination: urgent email, urgent SMS, routine email, routine SMS and so on. A notification abstraction can instead hold a reference to a delivery implementation. New notification types and delivery channels can evolve independently.
Composite organizes objects into tree structures and allows clients to treat individual objects and groups uniformly. It is useful for menus, file systems, organizational structures, document trees and nested user-interface components.
A document can contain paragraphs and sections; a section can contain other sections. If each node exposes operations such as render or search, client code can work with the root without manually checking whether each child is a leaf or a group.
The pattern is most useful when the domain is naturally hierarchical. It should not be forced onto flat collections that do not need recursive behaviour.
Decorator adds behaviour to an object by wrapping it with another object that exposes the same interface. It provides an alternative to creating many subclasses for combinations of optional features.
A data reader might be wrapped with compression, encryption, caching or metrics. Each decorator adds one responsibility while delegating the core operation to the wrapped component. Decorators can be combined in different orders to create different compositions.
Python also has function decorators, which apply related ideas to functions and methods. A decorator can add timing, logging, authorization or caching while preserving the original function's core responsibility. Use functools.wraps when writing decorators so metadata such as the original function name and documentation is retained.
Decorators should remain transparent about their behaviour. Excessive layers can make execution order, debugging and performance harder to understand.
Facade provides a simplified interface to a complex subsystem. It is useful when a client should perform a common task without coordinating several lower-level components.
An order-processing facade might validate an order, calculate a total, reserve inventory and request payment through internal services. The facade offers a focused entry point while the underlying components remain separately testable.
A facade should simplify access, not become a giant class that accumulates every business rule in the application. If it grows too large, separate the workflows or introduce more focused application services.
Flyweight reduces memory use by sharing common, immutable state across many objects. It is useful when an application creates very large numbers of similar objects and profiling shows that repeated shared data is a meaningful memory cost.
A text editor may represent each character with a small object. Font family, size and style can be shared between many character instances, while each character retains its own position and content. The shared intrinsic state is separated from context-specific extrinsic state.
Flyweight is an optimization, not a default modeling technique. Measure memory use first, and ensure shared state cannot be mutated in ways that unexpectedly affect every object using it.
Proxy provides a substitute object that controls access to another object. It can support lazy initialization, access control, caching, logging, remote communication or lifecycle management.
A virtual proxy delays loading a large resource until it is needed. A protection proxy checks permissions before delegating an operation. A remote proxy presents a local-looking interface to an object accessed over a network. A caching proxy stores selected results to avoid repeated expensive work.
A proxy should preserve the expectations of the interface it represents. Network proxies, in particular, must make latency, timeouts and failure behaviour explicit rather than pretending that remote operations are identical to local method calls.
Behavioral patterns focus on how objects communicate, delegate work and manage changing responsibilities. They are useful when interaction logic is becoming tangled or when behaviour needs to vary independently from the objects that use it.
Chain of Responsibility passes a request through a sequence of handlers. Each handler can process the request, reject it or pass it to the next handler.
HTTP middleware is a familiar example. A request may pass through logging, authentication, rate limiting, validation and routing. Each stage has a focused responsibility and can stop the chain when a condition is not met.
The order of handlers matters. Document the sequence and make it clear whether a handler can short-circuit processing, modify the request or transform the response.
Command encapsulates an operation as an object or callable. This separates the code that requests an action from the code that performs it and makes operations easier to queue, log, retry or undo.
A background job system can represent work as commands containing the data needed to execute an operation. A text editor can store commands in a history stack to support undo and redo. A task scheduler can queue commands for later execution.
Commands that are retried must be designed carefully. If an operation charges a payment or sends an irreversible message, executing the same command twice may have consequences. Use idempotency keys, durable state and explicit retry rules where appropriate.
Interpreter defines a representation for a small language and provides a way to evaluate sentences in that language. It is useful when a product needs a constrained expression format, such as a filtering language, rules engine or simple query syntax.
For example, a reporting application may let users define conditions such as status equals active and total greater than a specified value. A parser can convert the expression into a structured representation, and an interpreter can evaluate it against records.
For complex languages, use a dedicated parser or established expression engine rather than building a fragile interpreter from nested conditional statements. Security boundaries are essential: never evaluate arbitrary user input as executable code.
Iterator provides a consistent way to traverse a collection without exposing its internal representation. It allows a caller to process elements one at a time.
Python's iteration protocol uses iter and next, and generators provide a concise way to produce values lazily. Iterators are useful when working with large files, database result sets or streams where loading every item into memory would be wasteful.
An iterator should have a clear lifecycle. If it wraps a database cursor or file, callers must know who closes the underlying resource and what happens when iteration stops early.
Mediator centralizes communication between a set of components so that they do not need direct references to one another. It is useful when many components have complex, interdependent interactions.
A user-interface dialog may coordinate a form, validation messages, buttons and dependent fields. Instead of each component knowing about every other component, they communicate through the dialog mediator.
The risk is that the mediator can become a central object that knows too much. Keep its responsibilities focused and split large workflows into smaller coordinators when necessary.
Memento captures and stores an object's state so it can be restored later without exposing the object's internal representation. It is useful for undo operations, checkpoints and version history.
A document editor can save snapshots before major changes. A workflow engine can record a checkpoint that supports recovery after a controlled interruption. For large states, storing complete snapshots may be expensive; incremental changes or event logs may be more efficient.
State snapshots should be versioned when the structure may change over time. Restoring old data into a newer application version requires explicit compatibility rules.
Observer establishes a one-to-many relationship in which interested subscribers are notified when a subject publishes a change or event. It is useful for user-interface updates, domain events and in-process notifications.
For example, when an account is created, separate handlers might send a welcome message, write an audit record and update an internal metric. The account workflow publishes an event rather than importing every downstream implementation.
In a distributed application, an in-process Observer is not the same as a durable message broker. If notifications must survive process restarts or be delivered across services, use a persistent messaging mechanism and design for duplicate delivery, ordering and eventual consistency. The guide to microservices architecture explains how event-based communication fits into distributed systems.
State allows an object to change its behaviour when its internal state changes. It replaces sprawling conditional logic with state-specific behaviour and explicit transitions.
An order may move through pending, confirmed, paid, fulfilled, cancelled and refunded states. Not every transition is valid from every state. Separate state objects or a well-defined state machine can make allowed operations explicit.
For workflows with important business consequences, record transitions and validate them centrally. A State pattern should not allow arbitrary state changes that bypass domain rules.
Strategy defines a family of interchangeable algorithms and allows the appropriate one to be selected at runtime. It is useful when a process has several legitimate ways to perform the same task.
Examples include pricing calculations, shipping costs, authentication policies, ranking algorithms and file export formats. The caller uses a common contract and does not need to know the internal algorithm.
Python can implement Strategy with simple functions or with classes that satisfy a Protocol. The class-based approach is useful when an algorithm needs configuration or state; a function is often simpler when it does not.
from typing import Protocol
class DiscountPolicy(Protocol):
def calculate(self, subtotal: float) -> float:
...
class NoDiscount:
def calculate(self, subtotal: float) -> float:
return 0.0
class PercentageDiscount:
def __init__(self, percentage: float) -> None:
if not 0 <= percentage <= 100:
raise ValueError("percentage must be between 0 and 100")
self.percentage = percentage
def calculate(self, subtotal: float) -> float:
return subtotal * self.percentage / 100
def total_after_discount(
subtotal: float,
policy: DiscountPolicy,
) -> float:
discount = policy.calculate(subtotal)
return max(0.0, subtotal - discount)
policy = PercentageDiscount(10)
print(total_after_discount(200.0, policy))
The checkout workflow depends on the policy contract rather than a specific discount class. A new policy can be introduced without rewriting the total calculation. Python's Protocol supports structural typing for this kind of interface; see the Python typing documentation.
Template Method defines the high-level steps of an algorithm while allowing subclasses to customize selected steps. It is useful when several workflows share the same overall sequence but differ in specific operations.
A data import pipeline might always validate input, transform records, persist results and report completion. Different import formats can supply their own parsing and transformation steps while the shared process remains consistent.
Use Template Method when the sequence itself is an invariant. If the steps need to be rearranged frequently or selected dynamically, composition or Strategy may be a better fit.
Visitor separates an operation from the object structure on which it operates. It is useful when a stable set of element types must support several operations that would otherwise clutter those element classes.
A compiler can represent expressions as an abstract syntax tree and use visitors for validation, formatting or code generation. Each visitor implements an operation across the different node types.
Visitor can make it easier to add new operations, but adding a new element type may require updating every visitor. It is most suitable when the element hierarchy is relatively stable and the operations change more frequently.
The GoF catalogue is not a complete list of useful software design techniques. Modern applications use patterns that address application architecture, data access, distributed systems and functional composition.
Dependency Injection supplies a component's dependencies from outside rather than having the component construct them internally. It improves testability and makes infrastructure choices easier to change.
A service that sends invoices should receive an email sender through its constructor or function arguments. Production can provide an SMTP or provider-backed implementation; tests can provide a fake that records messages. The service does not need to know how the sender is configured.
Dependency injection is a technique, not a requirement to adopt a large framework. Constructor injection and explicit composition at the application entry point are often enough. Avoid service locators that hide dependencies behind global lookups.
Repository provides a collection-like interface for accessing domain objects while hiding persistence details. It can help keep domain logic independent of SQL queries or document-store APIs.
A repository is useful when it protects a meaningful domain boundary or centralizes complex persistence behaviour. It can become redundant when it simply duplicates every method of an ORM without adding clarity. Choose the abstraction based on the needs of the application, not because every tutorial includes a repository class.
Unit of Work tracks a set of changes made during a business operation and coordinates their persistence. It is often used with repositories and transaction boundaries.
The pattern helps make commit and rollback behaviour explicit. It is particularly useful when one business operation updates several related entities in the same transactional database. It does not create a distributed transaction across independent services.
Specification represents a business rule as an object or composable expression that can be evaluated against a candidate. It is useful when selection or validation rules are reused in several places.
For example, an eligibility specification might determine whether an account qualifies for a service based on status, region and account age. Specifications can be combined with logical AND, OR and NOT operations. Keep the rules readable; a custom rule engine is not justified for a handful of straightforward conditions.
Distributed applications use resilience patterns to handle unreliable dependencies. A circuit breaker temporarily stops calls to a failing dependency after a defined failure threshold, allowing it time to recover. Retry repeats an operation when a failure is likely to be transient.
Retries should be bounded and use backoff with jitter. They must also respect timeouts and operation semantics. Retrying a read request may be safe, while retrying a payment capture without an idempotency key may create duplicate charges. These patterns belong to reliability design and should be applied with a clear understanding of the failure mode.
Event Sourcing stores state changes as an ordered sequence of events rather than keeping only the latest state. CQRS separates the model used to change data from the model used to query it. These approaches can be useful in systems with strong audit requirements, complex histories or distinct read and write workloads.
They also introduce operational and conceptual costs: event versioning, projections, replay, consistency delays and more complicated debugging. They are not default replacements for ordinary CRUD operations.
Python offers language features that can express many pattern ideas without large class hierarchies. Functions are first-class values, decorators can wrap behaviour, generators implement lazy iteration, context managers manage resources and Protocol supports structural interfaces.
A Strategy may be a function passed as an argument. A Factory may be a dictionary mapping validated keys to constructors. An Iterator may be a generator. A Decorator may be a function wrapper. The goal is to preserve the design benefit, not reproduce a Java class diagram line by line.
The abc module supports abstract base classes that prevent incomplete implementations from being instantiated. They are useful when a framework or plugin system needs explicit runtime enforcement of required methods.
For type checking, Protocol can describe the methods a component must provide without requiring inheritance. Choose the mechanism that matches the project's needs and the team's familiarity.
A decorator can add timing or logging around a function without changing its business logic. Keep decorators small, preserve metadata with functools.wraps and make sure exceptions are not silently swallowed.
Files, locks and database transactions have lifecycles. Context managers make acquisition and cleanup explicit, including when an exception occurs. Python's contextlib module provides utilities for building context managers and composing resource handling.
Module-level constants and immutable configuration can be convenient. Global mutable service objects, caches and clients can make tests unpredictable and create hidden coupling. Prefer explicit application setup and pass dependencies to the components that need them.
For practical language foundations, see the Python programming guide. The Python testing guide also covers techniques that help verify behaviour behind these abstractions.
Consider a product that must send account and order notifications through email and SMS. The first implementation might place provider-specific code directly inside account registration and order-processing functions. That works initially, but adding a new provider or changing message delivery rules requires editing several business workflows.
A more maintainable design can combine several patterns:
The architecture might be represented as:
Account or Order Workflow
|
Domain Event
|
Notification Handler
|
Delivery Strategy
|
Provider Adapter
/ Email SMS
Provider Provider
The important point is not the number of patterns used. It is the separation of business events, delivery decisions and provider-specific details. Each boundary has a clear purpose and can be tested independently.
A production implementation should also decide whether delivery is synchronous or asynchronous, how failures are retried, how duplicate events are handled, where delivery status is stored and how sensitive information is protected. Patterns clarify the structure; they do not replace these operational decisions.
Choosing a pattern begins with understanding the problem rather than searching for a pattern name.
If the algorithm varies, consider Strategy. If object creation varies, consider a Factory. If a complex object requires staged construction, consider Builder. If an external interface differs from the application's contract, consider Adapter. If several objects need to react to an event, consider Observer or a durable event-driven mechanism.
Ask which component knows about which other component. If high-level business logic imports provider SDKs or database details, introduce an appropriate boundary. If several components depend on one concrete implementation, a shared interface may allow them to vary independently.
A function, dictionary, conditional or small module may solve the problem without an elaborate pattern. Compare the proposed design with the simplest alternative and consider the cost of future changes, not just the number of lines of code.
An abstraction is useful only when developers can understand and use it correctly. Prefer familiar language features and established conventions. Document non-obvious design decisions, especially where the pattern controls resource lifecycles, retries or state transitions.
A pattern should create useful seams for testing. A Strategy should allow each algorithm to be tested independently. An Adapter should be tested against the contract it implements. A Factory should return the expected implementation for supported configuration. An Observer should define what happens when a subscriber fails.
For broader API boundaries and contract design, see API design fundamentals and Swagger and OpenAPI documentation standards.
A pattern should solve a specific problem. Adding a Factory, Repository and Manager class to every feature can create layers that merely forward calls. The resulting code has more files but no clearer responsibilities.
Global instances hide dependencies and complicate tests. A shared service should normally have an explicit owner and lifecycle. Use application-level dependency injection when possible.
An interface with one implementation is not automatically valuable. Abstractions are useful when they protect a boundary, represent a meaningful contract or enable real variation. Otherwise they can add navigation and maintenance overhead.
Deep inheritance hierarchies can create fragile base classes and unexpected coupling. Prefer composition when behaviours need to be combined or replaced independently.
A class-level pattern does not define the architecture of an entire application. Microservices, layered architecture, hexagonal architecture and event-driven architecture operate at broader levels. A system can use Strategy or Adapter internally whether it is a monolith or a distributed application.
A pattern that works in a single-threaded demonstration may fail under concurrent requests. Shared mutable state, singleton initialization, event subscribers and resource cleanup require explicit design.
An Adapter or Proxy should not silently convert every error into success. A retry mechanism should not hide permanent failures. Keep error semantics clear and preserve enough context for diagnosis.
Flyweight, caching proxies and elaborate object pools are often introduced in response to imagined performance problems. Profile first, identify the bottleneck and then apply an optimization that can be measured.
Patterns should make behaviour easier to verify, not make tests dependent on implementation details.
Start with unit tests for the core behaviour of each strategy, handler, state or adapter. Test factories for valid and invalid configuration. Test decorators for both the added behaviour and correct delegation to the wrapped component. Test state machines for allowed and rejected transitions.
Use contract tests when multiple implementations are expected to satisfy the same interface. A payment adapter, for example, should satisfy the same application-level expectations regardless of provider. Integration tests can then verify that the real adapter communicates correctly with the external service.
Avoid mocking every internal class simply because the design contains many abstractions. Excessive mocking can make tests pass while the real components do not work together. Keep a balanced test suite: focused unit tests, contract tests at important boundaries, integration tests for infrastructure and a small number of end-to-end tests for critical user journeys.
Patterns also need maintenance. Revisit abstractions when a product's requirements change. A Strategy with two meaningful implementations may be appropriate; a Strategy with dozens of nearly identical classes may need consolidation. A Facade may start as a useful entry point but become too broad as features accumulate. Refactoring is part of keeping a pattern useful.
For practical deployment and runtime concerns, the guide to Docker containers and containerization explains how application components are packaged and run consistently across environments.
Design patterns and architectural patterns solve related but different problems. A design pattern usually addresses collaboration between objects or components. An architectural pattern shapes the major structure and boundaries of an application.
Layered architecture separates responsibilities such as presentation, application logic and persistence. Hexagonal architecture, also called Ports and Adapters, places business logic behind ports and uses adapters to connect external technologies. Clean Architecture emphasizes dependency direction so that business rules remain independent of frameworks and infrastructure. Event-driven architecture uses events to coordinate components that do not need to communicate through direct synchronous calls. Microservices architecture separates selected business capabilities into independently deployable services.
These architectural approaches can use the GoF patterns internally. An Adapter can implement a hexagonal port. A Factory can assemble infrastructure implementations at startup. Observer-like event handling can support an event-driven workflow. Strategy can select a business policy inside a modular monolith or a microservice.
The architectural choice should follow the system's scale, domain, team structure and operational requirements. A modular monolith can use excellent design patterns without needing a distributed deployment. A microservices system can still be poorly designed if its internal dependencies are tangled. Good local design and good system architecture reinforce one another, but neither guarantees the other.
Use this checklist during design discussions and code reviews:
If the pattern adds more concepts than it removes, reconsider the design. A successful pattern makes a difficult decision easier to express and maintain.
The following resources provide additional explanations and language-specific guidance:
Software design patterns are reusable approaches to common software design problems. They describe how responsibilities and interactions can be organized, but they are not complete code templates. Developers adapt them to the language, architecture and requirements of a particular application.
The classic Gang of Four patterns are grouped into creational, structural and behavioral categories. Creational patterns address object creation, structural patterns address composition and relationships, and behavioral patterns address communication and the distribution of responsibilities.
The classic GoF catalogue describes 23 patterns. They remain influential, although modern software engineering also uses many other patterns and techniques, including dependency injection, repository, unit of work, event sourcing and CQRS.
Start with Strategy, Factory Method, Adapter, Decorator, Observer, State and Facade. These patterns address common problems in application development and are easy to connect to practical examples. Learn the underlying design principles before trying to memorize every pattern.
The core ideas are language-independent, but implementations differ. Python may use functions, decorators and Protocols where Java uses interfaces and classes. JavaScript and TypeScript may use closures, objects and higher-order functions. Apply the intent of a pattern in an idiomatic way for the language.
Yes. Frameworks and languages provide many built-in abstractions, but developers still need to manage dependencies, object creation, communication, state and variation. Patterns remain useful as a shared vocabulary for these decisions. They should be applied selectively rather than treated as mandatory structures.
A design pattern usually addresses a smaller-scale problem involving objects or components. An architectural pattern describes the major organization of an application or system. Adapter is a design pattern; layered architecture and microservices are architectural approaches.
Singleton can be appropriate when one instance per process is a genuine requirement and its lifecycle is controlled. It is often overused as a shortcut for global access, which hides dependencies and makes testing harder. Explicit dependency injection is usually more flexible.
Strategy selects an interchangeable algorithm or policy, often based on configuration or context. State changes an object's behaviour according to its current lifecycle state and valid transitions. Both use composition, but they model different kinds of variation.
Factory Method delegates the creation of one product to a method or specialized creator. Abstract Factory provides an interface for creating a family of related products that should work together. Abstract Factory is useful when several product types must vary as a compatible set.
Some patterns can support performance by enabling caching, lazy initialization, resource sharing or more efficient algorithms. Others add indirection and object allocation. A pattern should not be assumed to improve speed; profile the application and measure the result.
No. Small applications may not need explicit patterns, and many frameworks already provide common solutions. Use a pattern when it makes a real design problem easier to solve, test or maintain. Avoid adding abstractions solely to make code appear sophisticated.
Software design patterns provide a practical vocabulary for solving recurring design problems. Creational patterns help control object creation, structural patterns organize relationships and composition, and behavioral patterns make communication and responsibility clearer. Modern techniques such as dependency injection, repositories, event handling and resilience patterns extend those ideas into application and distributed-system design.
The most important skill is knowing when a pattern is useful. Start with the actual problem, understand the responsibility that needs to change and compare the pattern with a simpler alternative. Favor clear boundaries, explicit dependencies, composition and focused interfaces. Test the resulting behaviour and revisit the abstraction when the application evolves.
Good software is not defined by how many patterns it contains. It is defined by how reliably it meets its requirements and how confidently developers can understand, change and operate it. Treat design patterns as tools for achieving those outcomes—not as goals in themselves.

Full-stack churn prediction platform using React, Django REST Framework, XGBoost, and SHAP. Enables telecom providers to identify at-risk customers, understand churn drivers, and support data-driven retention strategies.

Learn the 23 Gang of Four design patterns, modern application and distributed-system patterns, practical examples, trade-offs, and how to choose the right solution.
Read
Learn how to design maintainable, scalable, secure, and reliable software systems. Explore architecture styles, system design trade-offs, data, APIs, resilience, cloud deployment, and a practical design walkthrough.
Read
Explore the technical foundations and professional skills modern software engineers need to design, build, secure, test, deploy, and maintain reliable software.
Read