Home › Blog › Design patterns interview questions with examples

Design patterns interview questions with examples

Design pattern interviews test whether you recognise common solutions to recurring design problems and, more importantly, when to apply them. Expect questions on the three families — creational, structural and behavioural — with the patterns that appear in real codebases: Singleton, Factory, Builder, Adapter, Decorator, Facade, Strategy, Observer, Command and State. Interviewers reward a concrete example of each and an honest view of the costs, especially of Singleton.

Twelve common design pattern questions

  1. What are design patterns, and what are the three categories?
  2. Explain the Singleton pattern. What are its problems?
  3. Factory Method versus Abstract Factory?
  4. When would you use the Builder pattern?
  5. Adapter versus Facade versus Decorator?
  6. Explain the Strategy pattern with an example.
  7. Explain the Observer pattern. Where is it used?
  8. What is the Command pattern?
  9. What is the State pattern, and how does it differ from Strategy?
  10. What is dependency injection, and how does it relate to patterns?
  11. Which patterns have you used in real projects?
  12. When is using a pattern a mistake?

The patterns that come up most

PatternFamilyUse it whenEveryday example
SingletonCreationalExactly one instance must existA configuration registry (often better injected)
Factory MethodCreationalSubclasses decide which object to createCreating a parser per file type
BuilderCreationalObjects have many optional parametersConstructing HTTP requests
AdapterStructuralMake an incompatible interface fitWrapping a third-party payment SDK
DecoratorStructuralAdd behaviour without subclassingAdding caching or logging around a service
FacadeStructuralSimplify a complex subsystemOne checkout() call hiding inventory, payment, shipping
StrategyBehaviouralSwap algorithms at runtimePricing rules, sorting strategies
ObserverBehaviouralNotify subscribers of changesEvent listeners, UI data binding
CommandBehaviouralEncapsulate actions as objectsUndo/redo, job queues
StateBehaviouralBehaviour depends on internal stateOrder 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

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