I’ll be honest: the first time I opened a design patterns book, I closed it twenty minutes later. Words like “Flyweight” and “Visitor” sounded like they belonged in a medieval court, not a codebase.
What finally worked was ignoring the code and asking, “Where have I already seen this in real life?” Turns out, you’ve seen all of them too. Here’s my cheat sheet.
Creational Patterns: How Things Get Made
Factory. Think of a pizza shop. You say “pepperoni” and a pizza shows up. You don’t care how the dough was stretched, you just want pizza.
Abstract Factory. This is the furniture store that sells matching sets. Pick “modern” and you get a modern chair, table, and sofa that all work together. Pick “vintage” and the whole vibe changes.
Builder. Ever ordered a custom sandwich? Bread, then meat, then veggies, then sauce, one step at a time. You end up with exactly what you wanted, and you didn’t need one giant order with 15 options.
Prototype. It’s photocopying a document instead of retyping it. Need ten of something similar? Copy it and tweak the copy.
Singleton. A country has one president at a time. No matter who you ask, they all point to the same person. (In code, be careful with this one. It’s the pattern people overuse the most.)
Structural Patterns: How Things Fit Together
Decorator. Ice cream with toppings. The ice cream stays the same, but every topping adds something new. Sprinkles, then caramel, then more sprinkles, because why not.
Adapter. The travel plug that lets your US charger work in a European outlet. Neither side changes. The adapter just sits in the middle and makes them compatible.
Facade. A hotel concierge. Instead of calling the restaurant, the taxi company, and the tour guide yourself, you make one request and they handle the mess behind the scenes.
Bridge. Remote controls and TVs. Any remote can work with any TV brand because they agree on a common way to talk. You can swap either side without breaking the other.
Composite. Folders and files on your computer. A folder can hold files or more folders, and you can copy, move, or delete any of them the same way.
Flyweight. Imagine an old printing press. It doesn’t carve a new “e” for every “e” on the page. It reuses the same block over and over. Same idea: share what’s identical, save the memory.
Proxy. The receptionist who screens calls for a busy CEO. They stand in for the CEO, decide who gets through, and sometimes handle things on their own.
Behavioral Patterns: How Things Talk to Each Other
Command. A restaurant order slip. The waiter writes down your request, hands it over, and the kitchen handles it later. The request becomes a thing you can queue, pass around, or even cancel.
Chain of Responsibility. Customer support. The agent tries first, then the supervisor, then the manager, until someone can actually fix your problem.
Observer. Subscribing to a YouTube channel. You don’t keep checking for new videos. When one drops, you get notified.
Interpreter. A translator at a meeting, turning one language’s rules into something the other side understands.
Iterator. Flipping through TV channels with the “next” button. You don’t know (or care) how the channels are stored. You just keep pressing next.
Mediator. Air traffic control. Planes don’t chat with each other directly. They all talk to the tower, and the tower keeps everyone from colliding.
Memento. The save point in a video game, or Ctrl+Z. You can always go back to how things were.
State. A traffic light. Same light, completely different behavior depending on whether it’s red, yellow, or green.
Strategy. Getting to work. You can drive, bike, or take the train. The goal is the same, but you swap the method depending on the day.
Template Method. A recipe skeleton: prep, cook, serve. The steps are always in that order, but every dish fills in its own details.
Visitor. A tax inspector visiting different kinds of businesses. A bakery and a law firm get checked differently, but neither has to change how it operates for the inspector to do the job.
The Takeaway
You don’t need to memorize all 23 patterns. Honestly, most developers regularly use maybe five or six. The real value is recognizing the problem when you see it: “Oh, I’m basically building a pizza shop here,” or “This is just a concierge.”
Once the analogy clicks, the code is the easy part.