Which Pattern Do I Need?

A problem-first guide for picking the right design pattern, telling look-alike patterns apart, and spotting when you don't need a pattern at all.

Intermediate⏱ 3 min readLesson 6 of 6#design-patterns#cheat-sheet#decision-guide

Start from the pain, not the pattern

Find your problem in the left column, then follow the arrow.

Drawing diagram…

Look-alike patterns

Several patterns have the same code shape but different intent. The intent is what matters.

These look alike…The difference
Decorator vs ProxyDecorator adds behaviour. Proxy controls access to the same behaviour.
Adapter vs FacadeAdapter makes one interface fit another. Facade simplifies many interfaces into one.
Strategy vs StateIn Strategy the caller chooses. In State the object changes itself.
Factory vs BuilderFactory creates in one call and decides the type. Builder creates step by step.
Observer vs MediatorObserver broadcasts one-to-many. Mediator coordinates many-to-many through a hub.
Command vs Memento (undo)Command stores operations to reverse. Memento stores snapshots to restore.
Composite vs DecoratorBoth wrap objects. Composite groups many children; Decorator wraps exactly one.
Drawing diagram…

The top 8 to learn first

If you only have time for a few, learn these. They cover most real-world code:

  1. 🏭 Factory — creating the right object from config or input
  2. 🔌 Adapter — wrapping 3rd-party libraries
  3. ☕ Decorator — middleware, HOCs, retry/cache/log wrappers
  4. 🏨 Facade — service layers and SDKs
  5. 📰 Observer — events everywhere, UI and backend
  6. 🗺️ Strategy — pluggable algorithms (payments, pricing, auth)
  7. 🚦 State — order and payment workflows
  8. 📞 Chain of Responsibility — request pipelines

Anti-patterns: when patterns go wrong

Anti-patternWhat it looks likeBetter
PatternitisAbstractSingletonProxyFactoryBean for a one-off taskPlain function first
Singleton abuseGlobal state everywhere, flaky testsDependency injection
God objectOne class that knows and does everythingSplit by responsibility (SRP)
Premature abstractionInterfaces with a single implementation "for flexibility"Wait for the second use case
Golden hammer"We use Observer for everything"Pick per problem

💡 The best pattern is often no pattern. A clear function with a good name beats a textbook pattern applied to a problem you don't have.

Patterns at system scale

The same ideas reappear when you design whole systems, which you'll meet later in the Microservices and Kafka lessons:

Object-level patternSystem-level cousin
ObserverPub/Sub, Kafka topics, event-driven architecture
FacadeAPI Gateway, Backend for Frontend
ProxyReverse proxy, CDN, service mesh sidecar
AdapterAnti-corruption layer
CommandMessage queues, CQRS commands
MediatorSaga orchestrator
Chain of ResponsibilityMiddleware pipelines, API gateway filters
MementoEvent sourcing snapshots

Key takeaways

  • Start from the problem you have, then pick the pattern.
  • Look-alike patterns differ in intent, not code shape.
  • Learn the top 8 first; they cover most real code.
  • Avoid patternitis: add a pattern when simple code starts to hurt.
  • Object patterns scale up into system architecture patterns.