Foundations · 6 min

What a design pattern is (and isn't)

One definition, three common misconceptions, and how to use patterns without turning your code into a museum.

Definition

A design pattern is a named solution to a recurring design problem. It has three parts: the problem (when it shows up), the solution (who talks to whom), and the cost (what it makes heavier).

The most valuable part isn't the code — it's the name. When you say "this should be pulled out into a Strategy", your teammates immediately get the intent, the scope of the change, and the risk. A shared vocabulary saves hours of arguing in code review.

What a pattern is not

  • Not an algorithm. An algorithm solves a computational problem (sorting, shortest path). A pattern solves a code structure problem (who calls whom, who creates which object).
  • Not a snippet to copy. Two problems that both use Observer can look nothing alike. What gets reused is the structure of the relationships, not the lines of code.
  • Not a standard. Nobody is stopping you from writing if/else. A pattern is a choice, and choices come with a price.
  • Not proof that you're good. Building 7 abstract factories for a 3-field form doesn't make the code more "pro" — it just makes more files.

Patterns vs design principles

Principles (SOLID, DRY, separation of concerns, composition over inheritance) are the why; patterns are how that why gets implemented in a specific situation. Strategy exists because of Open/Closed and because of Dependency Injection.

Learn patterns without the principles and you'll apply the right form at the wrong time. That's why every pattern on this site has a "Don't use when" section.

How to read a pattern article on this site

  • Read the Problem first. If it has never hurt you, make a note and move on — the pattern will find you when you need it.
  • Code along step by step. Every step prints something; don't jump to the last one.
  • Edit the demo in the Try it section: change a number, add a branch, break it, then fix it. That's the fastest way to get a pattern into your hands.
  • Read the Don't use when section last — it matters as much as everything else.