When Design Patterns Become Anti-Patterns
Design patterns solve recurring software design problems, but applying them without a clear purpose can introduce unnecessary complexity. Learn how to recognize overengineering, evaluate abstractions, and choose designs that make software easier to understand, test, and change.
Table of Contents
- Introduction
- 1. The Problem: Applying Patterns Without Understanding the Problem
- 2. Overengineering: When Abstraction Costs More Than It Saves
- 3. The Abstraction Trap: More Layers Do Not Mean Better Architecture
- 4. Revisiting the Patterns: When Not to Use Them
- 5. Recognizing Common Design Anti-Patterns
- 6. How to Decide Whether a Pattern Is Worth Introducing
- 7. Refactoring Toward Simplicity
- 8. Design Patterns and the Cost of Change
- Summary
Introduction
Design patterns are often presented as reusable solutions to recurring software design problems.
The Strategy Pattern helps replace complicated conditional logic with interchangeable behavior. Factory patterns centralize object creation. Dependency Injection separates construction from usage. Observer and Chain of Responsibility help decouple components. Repository and Unit of Work establish useful boundaries around persistence.
Each pattern addresses a recognizable problem.
But there is a subtle risk in learning design patterns: once developers understand a pattern, they may start looking for opportunities to apply it everywhere.
A simple function becomes a strategy interface. A constructor becomes a factory. A database query gets wrapped in a repository. A handful of related operations turn into a framework of handlers, commands, and abstractions.
The resulting code may look more sophisticated, but sophistication is not the same as good design.
Every abstraction introduces a cost. Developers must learn it, navigate it, maintain it, and understand how it interacts with the rest of the system. If the abstraction does not solve a meaningful problem, that cost is wasted.
This leads to the central idea of this article:
A design pattern becomes an anti-pattern when its use consistently makes the system harder to understand, change, or operate than a simpler alternative would.
The problem is not the pattern itself. The problem is applying a valid solution in a context where it does not provide enough value.
1. The Problem: Applying Patterns Without Understanding the Problem
Consider a function that calculates a discount.
function calculateDiscount(
customerType: string,
amount: number,
): number {
if (customerType === "regular") {
return amount * 0.05;
}
if (customerType === "premium") {
return amount * 0.1;
}
return 0;
}This function is simple. The behavior is visible, and a developer can understand it without navigating multiple files.
Now imagine replacing it with a Strategy Pattern implementation.
interface DiscountStrategy {
calculate(amount: number): number;
}
class RegularDiscount
implements DiscountStrategy
{
calculate(amount: number): number {
return amount * 0.05;
}
}
class PremiumDiscount
implements DiscountStrategy
{
calculate(amount: number): number {
return amount * 0.1;
}
}
class NoDiscount implements DiscountStrategy {
calculate(_amount: number): number {
return 0;
}
}
class DiscountService {
constructor(
private readonly strategy: DiscountStrategy,
) {}
calculate(amount: number): number {
return this.strategy.calculate(amount);
}
}This design is not inherently wrong. It separates discount behavior behind a common interface.
But it also introduces several classes, an interface, and an additional layer of indirection.
If the application has only three stable discount rules and no need to substitute, configure, or independently extend them, the abstraction may cost more than it saves.
The original function may be the better design.
Now change the requirements. Suppose discounts become configurable by market, customer segment, campaign, and subscription tier. Marketing teams can introduce new discount policies without modifying the checkout service. Different policies must be tested independently and selected dynamically.
The Strategy Pattern may now provide substantial value.
The difference is not the number of lines of code. It is the nature of the problem.
A pattern should be introduced because the design needs its properties, not because the pattern is available.
2. Overengineering: When Abstraction Costs More Than It Saves
Overengineering occurs when a solution introduces more structure, flexibility, or complexity than the current requirements justify.
It is not limited to design patterns, but patterns can make overengineering look intentional and professional.
2.1 Designing for hypothetical requirements
Imagine building an application that stores a small amount of user data in PostgreSQL.
A developer introduces:
- A generic repository framework.
- A repository factory.
- An abstract persistence provider.
- A database adapter interface.
- A storage strategy registry.
- A plugin system for hypothetical future databases.
The application now supports several ways to store data, even though only one implementation exists and there is no concrete plan to add another.
The problem is not that these abstractions are technically invalid. The problem is that the system is paying for flexibility before there is a demonstrated need for it.
A better starting point may be a straightforward implementation with a clear boundary around the database. If multiple storage implementations become necessary, the design can evolve then.
This does not mean waiting until a change becomes painful before preparing for it. It means distinguishing credible requirements from speculative possibilities.
2.2 Confusing extensibility with simplicity
A design can be easy to extend but difficult to understand.
For example, a request pipeline built around a generic handler registry may allow developers to add new processing steps without modifying existing handlers. That is valuable when the pipeline genuinely evolves.
However, if the application has only two fixed steps, the registry may obscure the execution order and make debugging harder.
Extensibility is one dimension of design quality, not the only one.
A good design balances:
- Ease of understanding.
- Ease of testing.
- Ease of changing behavior.
- Runtime reliability.
- Operational complexity.
- The cost of maintaining the abstraction itself.
The most extensible design is not automatically the best design.
2.3 Measuring abstraction by its actual benefit
When evaluating an abstraction, consider what it removes or makes safer.
Does it eliminate duplicated business rules? Does it prevent invalid states? Does it isolate an unstable dependency? Does it make a difficult workflow easier to test?
If the answer is unclear, the abstraction may not be doing enough.
A useful question is:
If this abstraction disappeared tomorrow, what concrete problem would the application have?
If the answer is merely that the architecture would look less sophisticated, that is not a strong justification.
3. The Abstraction Trap: More Layers Do Not Mean Better Architecture
Layered architecture can help separate responsibilities, but adding layers without meaningful boundaries can make a system harder to navigate.
Consider a simple HTTP endpoint that retrieves a user.
flowchart TD
A[HTTP Controller] --> B[User Application Service]
B --> C[User Manager]
C --> D[User Provider]
D --> E[User Repository]
E --> F[Database Adapter]
F --> G[ORM]
G --> H[(Database)]This structure might be justified in a large system where each layer owns a distinct responsibility.
But imagine that every layer simply forwards the same arguments to the next layer. There is no validation, policy, orchestration, mapping, or meaningful abstraction.
The developer must navigate eight layers to understand a database lookup.
That is not separation of concerns. It is separation of code into files without a corresponding separation of responsibility.
A better design starts with responsibilities
For a small application, the following may be sufficient:
flowchart TD
A[HTTP Controller] --> B[User Service]
B --> C[(Database)]As requirements grow, introduce boundaries where they solve specific problems.
For example:
- Add a repository when persistence behavior needs a meaningful application-facing contract.
- Add a Unit of Work when multiple writes must participate in one transaction.
- Add a Strategy when behavior must be interchangeable.
- Add a Command when an operation needs to be represented, queued, retried, or audited as data.
- Add a workflow engine when a process spans long-running steps and failure recovery.
The goal is not to minimize the number of layers at all costs. It is to ensure that each layer has a reason to exist.
4. Revisiting the Patterns: When Not to Use Them
Let's revisit the patterns covered in this series and examine the situations in which each may become unnecessary complexity.
4.1 Strategy Pattern
Useful when: Multiple interchangeable algorithms or policies need to be selected, tested, or extended independently.
Potential anti-pattern when: A few stable branches are replaced with separate classes without improving extensibility or clarity.
A small conditional can be the right solution. Use Strategy when separating behavior makes the system easier to change, not simply to remove every if statement.
4.2 Factory Pattern
Useful when: Object creation involves meaningful rules, configuration, dependency selection, or multiple implementation choices.
Potential anti-pattern when: A factory merely forwards arguments to a constructor.
function createUser(
id: string,
email: string,
): User {
return new User(id, email);
}This function may be perfectly reasonable, but it does not automatically need a dedicated factory abstraction.
Add a factory when creation is a responsibility worth separating.
4.3 Dependency Injection
Useful when: Components depend on replaceable collaborators, configuration, or infrastructure that should be supplied externally.
Potential anti-pattern when: A simple application introduces a large dependency injection container, complex registration conventions, and indirect resolution for a handful of dependencies.
Constructor injection with explicit composition is often sufficient. The purpose is to control dependencies, not to maximize the use of a container.
4.4 Observer Pattern
Useful when: Multiple independent consumers need to react to an event without tightly coupling the producer to each consumer.
Potential anti-pattern when: A simple, synchronous function call is replaced by a hidden event system that makes execution order, errors, and side effects difficult to trace.
If an operation must happen immediately and its result is required, an explicit function call may communicate the relationship more clearly.
4.5 Decorator Pattern
Useful when: Optional behavior such as logging, caching, or retry can be composed around an implementation without modifying its core behavior.
Potential anti-pattern when: A long stack of decorators makes execution order and error handling difficult to understand.
For example, combining retry, caching, timeout, logging, and circuit-breaking layers may be appropriate in an infrastructure client. But their ordering and interactions must be explicit.
A few clearly written functions may be easier to maintain when the behavior is not genuinely reusable or composable.
4.6 Adapter Pattern
Useful when: An external API, legacy component, or third-party SDK has an interface that does not match what the application expects.
Potential anti-pattern when: An adapter merely renames methods without translating incompatible data, semantics, errors, or behavior.
If the underlying interface already matches the application's requirements, an extra adapter may add little value.
4.7 Chain of Responsibility
Useful when: A request must pass through an extensible sequence of handlers, such as authentication, authorization, validation, and processing.
Potential anti-pattern when: A fixed sequence of two operations is hidden behind a generic pipeline framework.
The pipeline should clarify processing order and control flow. It should not make a simple sequence harder to follow.
4.8 Command Pattern
Useful when: Operations must be queued, scheduled, retried, audited, serialized, or handled independently of the code that initiates them.
Potential anti-pattern when: Every trivial method call is wrapped in a command object, invoker, registry, and dispatcher without a concrete need.
A function call is often sufficient for immediate work. Command becomes valuable when the operation needs a distinct lifecycle or representation.
4.9 State Pattern
Useful when: An object's behavior changes substantially according to its current state, and state-dependent rules are becoming difficult to manage.
Potential anti-pattern when: A small number of states with nearly identical behavior are represented by a large hierarchy of classes.
For a simple lifecycle, a discriminated union and a transition function may be clearer. For a complex workflow, dedicated state objects or an explicit state machine may be appropriate.
4.10 Repository Pattern
Useful when: Persistence operations need a meaningful boundary, domain-specific queries are reused, or application logic should not depend on ORM-specific details.
Potential anti-pattern when: The repository simply forwards every ORM method while exposing the same database types to callers.
Direct ORM usage can be reasonable when the ORM already provides the abstraction the application needs.
4.11 Unit of Work
Useful when: Multiple persistence operations must participate in the same transaction, with clear ownership of commit and rollback.
Potential anti-pattern when: A custom Unit of Work framework duplicates a simple transaction API without improving transaction safety or application structure.
The key is to guarantee that all participating repositories use the same transaction-scoped client. An elaborate abstraction that fails to enforce this invariant is worse than a simpler, correct implementation.
The common principle
Across all these patterns, the decision follows the same logic:
- Identify the concrete problem.
- Understand what the pattern changes about the design.
- Evaluate whether those properties are needed.
- Account for the complexity the pattern introduces.
- Prefer the simpler solution when the trade-off does not justify the abstraction.
5. Recognizing Common Design Anti-Patterns
A design pattern can be used poorly without becoming the only problem in the system. Several broader anti-patterns often appear alongside overuse of patterns.
5.1 The God Object
A God Object accumulates too many responsibilities.
A service might handle authentication, billing, notifications, persistence, reporting, and workflow orchestration because it is convenient to keep adding methods to the same class.
The solution is not necessarily to apply a pattern to every responsibility. First identify the responsibilities that change for different reasons, then separate them where doing so improves cohesion.
5.2 The Anemic Abstraction
An abstraction is anemic when it adds a layer without owning meaningful behavior or enforcing a useful contract.
A repository that forwards ORM methods is one example. A service that merely forwards every controller call to another service can be another.
The problem is not delegation itself. Delegation is useful when it separates responsibility. It is wasteful when every layer exists only to pass control along.
5.3 The Golden Hammer
The Golden Hammer is the tendency to apply a familiar solution to every problem.
A developer who has learned Strategy may try to remove every conditional. A developer who prefers event-driven architecture may turn every method call into an event. A developer who favors repositories may insist that every database operation must pass through one.
The antidote is to evaluate the problem before choosing the tool.
5.4 Premature Generalization
Premature generalization occurs when a design is made generic before the system has enough evidence to justify the abstraction.
A highly configurable workflow engine might be useful across several products. Building it for a single fixed workflow can be unnecessary.
Generalize when there are meaningful commonalities and real variation to support. Until then, a concrete implementation may preserve the same opportunities for future refactoring at a lower cost.
5.5 Hidden Control Flow
Event buses, decorators, middleware, and command dispatchers can make behavior modular, but they can also obscure what actually happens when an operation executes.
For example, a call to createOrder() may trigger inventory updates, emails, analytics, and external integrations through several indirect mechanisms.
That design may be justified, but the relationships must remain observable and understandable.
Use explicit naming, structured logs, tracing, clear error semantics, and documentation where necessary. Decoupling should not mean making behavior impossible to follow.
6. How to Decide Whether a Pattern Is Worth Introducing
A practical design decision should consider both the problem being solved and the cost of the solution.
Use the following framework before introducing a new abstraction.
Step 1: State the problem without naming a pattern
Avoid starting with statements such as:
- "We need Strategy here."
- "This service should use a Repository."
- "Let's add a Factory."
Instead, describe the observed problem:
- The same policy is duplicated in four services.
- Creating a payment client requires environment-specific configuration.
- Three database writes must commit atomically.
- Adding a new handler requires modifying several unrelated components.
A clear problem statement makes it easier to compare alternatives.
Step 2: Identify the required property
Different problems require different properties.
| Problem | Property to look for |
|---|---|
| Algorithms vary independently | Interchangeable behavior |
| Object construction is complex | Centralized creation |
| Dependencies should be replaceable | Dependency inversion |
| Multiple consumers react to events | Decoupled notification |
| External interfaces differ | Interface translation |
| Operations need queuing or retry | Explicit operation representation |
| Behavior depends on lifecycle state | State-dependent behavior |
| Persistence details leak into application logic | Persistence boundary |
| Multiple writes must commit together | Transaction coordination |
The pattern should provide a property that directly addresses the problem.
Step 3: Compare the simplest viable alternatives
Consider at least two options:
- A direct implementation using functions, conditionals, or existing library features.
- A pattern-based implementation with an explicit abstraction.
Evaluate both against the actual requirements.
For example, replacing a discount conditional with Strategy may improve independent extensibility. But if the policies are fixed and local, the conditional may remain simpler.
Do not assume the more abstract option is better by default.
Step 4: Estimate the cost of introducing the abstraction
The cost includes more than the initial code.
Consider:
- Additional interfaces and implementations.
- More concepts for developers to learn.
- More places to navigate when debugging.
- More tests and configuration.
- More opportunities for behavior to become indirect.
- Constraints imposed by the abstraction itself.
Then compare that cost with the duplication, coupling, or risk the abstraction removes.
Step 5: Revisit the decision when the requirements change
A pattern that is unnecessary today may become valuable later.
A conditional that initially expresses three stable rules may become a Strategy when rules become configurable. A direct database query may later move behind a repository when persistence behavior becomes complex.
Good design does not require predicting every future change. It requires making the current design understandable and preserving reasonable paths for evolution.
7. Refactoring Toward Simplicity
Avoiding overengineering does not mean avoiding patterns. It means introducing them incrementally when the problem becomes clear.
Suppose an application starts with:
function calculateShipping(
region: string,
weight: number,
): number {
if (region === "local") {
return weight * 1;
}
if (region === "international") {
return weight * 5;
}
throw new Error("Unsupported region");
}At first, this may be sufficient.
Later, the business adds carrier-specific rates, negotiated customer contracts, delivery speed, and package dimensions. Shipping policies now vary independently, and the calculation needs to be selected based on order context.
That is a natural point to introduce a Strategy interface.
interface ShippingStrategy {
calculate(
packageWeight: number,
): number;
}The abstraction emerges from a demonstrated variation point.
The refactoring process can follow a simple sequence:
- Keep the original implementation while the behavior remains simple.
- Identify the conditions or duplicated logic that make changes difficult.
- Extract a meaningful contract around the behavior that varies.
- Move implementations behind that contract.
- Keep selection logic separate from execution logic.
- Add tests that verify both the individual implementations and the selection rules.
The same reasoning applies to repositories, factories, commands, and other patterns.
Refactoring should improve the design's ability to express the requirements. It should not merely increase the number of design-pattern names in the codebase.
8. Design Patterns and the Cost of Change
Ultimately, design quality is closely related to how safely and efficiently a system can change.
A design that is easy to write but expensive to modify may become a maintenance burden. A design that is extremely flexible but difficult to understand can be equally problematic.
The goal is not minimum code, maximum abstraction, or maximum extensibility.
It is to make likely changes local, understandable, and safe.
Consider three possible designs for a payment integration.
Design A: Direct implementation
The checkout service constructs a payment SDK client and calls it directly.
This is simple, but configuration and provider-specific behavior may spread into the application.
Design B: Meaningful abstraction
The application depends on a payment interface. A concrete adapter translates the application's payment request into the provider's API. Dependency Injection supplies the adapter.
This is valuable when provider-specific behavior needs to remain isolated or multiple providers are supported.
Design C: Overengineered framework
The application introduces a generic provider registry, plugin discovery, dynamic configuration, multiple factory layers, a strategy resolver, and a workflow engine—even though it has one provider and no requirement for runtime extensibility.
Design B may provide the best balance. Design A may be entirely sufficient for a small internal tool. Design C may become justified in a platform that genuinely supports many providers and independent plugins.
There is no universal answer based on the number of patterns used.
The right design depends on the system's real constraints, the changes it must support, and the operational risks it must control.
A useful final test
Before accepting a pattern-based design, ask:
- Does it make the business rules easier to find?
- Does it reduce coupling in a meaningful way?
- Does it make important invariants easier to enforce?
- Does it improve testing without hiding production behavior?
- Does it reduce the cost of plausible future changes?
- Can a new developer understand why the abstraction exists?
If the answers are mostly no, reconsider the design.
Sometimes the best refactoring is to remove an abstraction, merge unnecessary layers, or replace a framework with a straightforward function.
Simplification is not a step backward when it makes the system clearer and safer.
Summary
Design patterns are valuable because they capture recurring solutions to software design problems. They are not valuable merely because they are recognizable or widely used.
Strategy, Factory, Dependency Injection, Observer, Decorator, Adapter, Chain of Responsibility, Command, State, Repository, and Unit of Work all provide useful design options. Each also introduces concepts and constraints that must be justified by the problem it solves.
Overengineering often begins when developers choose a pattern before understanding the problem, design for speculative requirements, or mistake additional layers for better separation of concerns.
A stronger approach is to identify the concrete problem, determine the property the solution must provide, compare simpler alternatives, and introduce the smallest abstraction that meets the requirement.
As the system evolves, revisit those decisions. Add structure when it reduces meaningful complexity, and remove structure when it no longer earns its cost.
The most important design skill is not knowing how to implement every pattern.
It is knowing when a pattern makes the system better—and when the simplest solution is already the right one.
- Design Patterns
- Repository Pattern
- OOP
- Programing
- Software Architecture
- YAGNI Principle
- Clean Code
- Overuse of Design Patterns