Twelve common design pattern questions
- What are design patterns, and what are the three categories?
- Explain the Singleton pattern. What are its problems?
- Factory Method versus Abstract Factory?
- When would you use the Builder pattern?
- Adapter versus Facade versus Decorator?
- Explain the Strategy pattern with an example.
- Explain the Observer pattern. Where is it used?
- What is the Command pattern?
- What is the State pattern, and how does it differ from Strategy?
- What is dependency injection, and how does it relate to patterns?
- Which patterns have you used in real projects?
- When is using a pattern a mistake?
The patterns that come up most
| Pattern | Family | Use it when | Everyday example |
|---|---|---|---|
| Singleton | Creational | Exactly one instance must exist | A configuration registry (often better injected) |
| Factory Method | Creational | Subclasses decide which object to create | Creating a parser per file type |
| Builder | Creational | Objects have many optional parameters | Constructing HTTP requests |
| Adapter | Structural | Make an incompatible interface fit | Wrapping a third-party payment SDK |
| Decorator | Structural | Add behaviour without subclassing | Adding caching or logging around a service |
| Facade | Structural | Simplify a complex subsystem | One checkout() call hiding inventory, payment, shipping |
| Strategy | Behavioural | Swap algorithms at runtime | Pricing rules, sorting strategies |
| Observer | Behavioural | Notify subscribers of changes | Event listeners, UI data binding |
| Command | Behavioural | Encapsulate actions as objects | Undo/redo, job queues |
| State | Behavioural | Behaviour depends on internal state | Order status, vending machines |
Singleton and its problems
Singleton ensures one instance with a global access point. Interviewers ask about it partly to hear its downsides: it's global state in disguise, it hides dependencies, it makes unit testing hard because you can't easily substitute a fake, and naive lazy initialisation isn't thread-safe. In most modern codebases, a dependency injection container creating one shared instance gives the same benefit without the drawbacks.
Distinctions that trip people up
- Factory Method vs Abstract Factory: one method that creates one product, overridden by subclasses, versus an object that creates families of related products (a UI toolkit's buttons and checkboxes for one theme).
- Adapter vs Facade vs Decorator: Adapter changes an interface to match another; Facade simplifies many interfaces into one; Decorator keeps the interface and adds behaviour.
- Strategy vs State: both delegate to swappable objects, but the client chooses a Strategy, while State objects switch themselves as the context's state changes.
Patterns you already use in frameworks
Many patterns are built into the tools you use daily, and pointing that out is a strong answer to “where have you used this?”. Dependency injection containers in Spring or .NET manage object creation and lifetimes. Middleware pipelines in Express or ASP.NET Core are chains of responsibility. Java's I/O streams and Python decorators wrap behaviour in the spirit of Decorator. React's component composition and hooks replace many classic inheritance-based patterns, and event emitters everywhere are Observer. Recognising these shows you understand patterns as ideas rather than class diagrams to memorise.
When patterns hurt
Patterns add indirection. Applying them before there's a need — a Factory with one product, a Strategy with one algorithm — makes code harder to read for no benefit. A good answer is that you introduce a pattern when a second or third variation appears, and that naming a pattern in a code review is useful shorthand, not a goal. Interviewers in object-oriented design interviews like hearing exactly this.
Practising
Interviewers follow up on the most specific thing you say, so rehearse the second question as well as the first. CoPilot Interview, a free AI interview assistant, runs design patterns mock interviews with follow-ups and produces a report of likely next-round questions. Prepare one real example from your own code for three patterns — interviewers nearly always ask “where have you used this?”. See also OOP interview questions.
Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly. Everything else on this page applies whichever tool you use, or none.
Frequently asked questions
What are the three categories of design patterns?
Creational patterns deal with object creation, structural patterns with composing classes and objects, and behavioural patterns with communication and responsibility between objects.
Why is Singleton considered an anti-pattern?
It introduces hidden global state, hides dependencies, complicates testing and can be unsafe under concurrency. Dependency injection of a shared instance usually works better.
What is the difference between Strategy and State?
Both delegate behaviour to swappable objects, but the client selects a Strategy, whereas State objects change the context's behaviour themselves as its internal state changes.
Which design patterns should I know for interviews?
Singleton, Factory, Builder, Adapter, Decorator, Facade, Strategy, Observer, Command and State cover most interview questions.
Practise on real interview questions
Run 145 real interview questions across 10 tracks, answer out loud and see a structured answer to compare with yours. Free, no signup.
Try a practice question