Interview Q&A · questions with model answers

Design Patterns Interview Questions

Part of the study plan for: Backend Engineer · Tech Lead

Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.

  1. Most asked What is a design pattern, and why are they useful?

    A design pattern is a named, reusable solution shape for a design problem that keeps recurring. Patterns give teams a shared vocabulary and proven trade-offs, so one word like "Strategy" can explain…

  2. Most asked What is dependency injection, and what forms does it take?

    Dependency injection means an object receives its collaborators from outside instead of creating them. The forms are constructor injection (the default), setter or property injection (optional or…

  3. Most asked What problem does the Builder pattern solve? Show an example.

    Builder assembles complex objects step by step with named, chainable methods and a final build() that validates the combination. It replaces telescoping constructors and unreadable positional…

  4. Most asked What is the Adapter pattern? Give an example.

    Adapter wraps a class that has an incompatible interface and translates calls to the interface your code expects. For example, a LegacyBillingAdapter implements your PaymentProvider.charge(cents) by…

  5. Most asked What is the Decorator pattern? How is it different from inheritance?

    Decorator wraps an object in another object with the same interface that adds behaviour before or after delegating. Unlike inheritance, decorators are combined at runtime and stack in any order, so…

  6. Most asked What is the Repository pattern, and when is it worth using?

    A repository is a collection-like interface (add, get, overdue_invoices()) that hides how domain objects are stored. It's worth using when business logic is mixed with queries and you want it…

  7. Most asked What are the three categories of Gang of Four design patterns?

    Creational patterns deal with object creation (Factory Method, Abstract Factory, Builder, Prototype, Singleton), structural patterns with composing objects (Adapter, Bridge, Composite, Decorator,…

  8. Most asked What is the Facade pattern?

    Facade provides one simple, task-focused interface to a complex subsystem. An OrderFacade.place_order() coordinates inventory, payments, shipping and email in the right order, so callers don't…

  9. Most asked What is MVC, and which design patterns does it combine?

    Model-View-Controller separates data and business rules (model), presentation (view) and input handling (controller). Classic MVC combines Observer (views observe the model), Strategy (the…

  10. Most asked What is an anti-pattern? Name a few common ones.

    An anti-pattern is a common response to a recurring problem that looks reasonable but usually causes more harm than good. Common ones: the god object, singleton used as a global variable, service…

  11. What does the Single Responsibility Principle mean in practice?

    A class (or module) should have one reason to change, meaning it serves one actor or concern. If finance's tax rules and design's PDF layout both live in Invoice, split them into a calculator and a…

  12. What kinds of Proxy are there, and what does each do?

    A proxy has the same interface as its subject and controls access to it. Kinds: virtual proxy (creates an expensive object lazily), protection proxy (checks permissions), caching proxy (returns…

  13. What is the State pattern? When would you use it?

    State moves each state's behaviour into its own class; the context object delegates to its current state, and states trigger transitions. Use it when the same switch on a status field appears in…

  14. What is the Circuit Breaker pattern?

    A circuit breaker wraps calls to a remote dependency and, after too many failures, "opens" to fail fast for a cool-down period instead of waiting on a broken service; it then lets a few trial calls…

  15. What is the Interface Segregation Principle?

    Clients shouldn't be forced to depend on methods they don't use. Prefer several small, role-focused interfaces (Printer, Scanner) over one large one (MultiFunctionDevice) that forces implementers to…

  16. What does "program to an interface, not an implementation" mean?

    Depend on what an object can do (its interface or methods) rather than its concrete class. Code that needs "something that can send()" works with email, SMS or a test fake without changes.

  17. What are coupling and cohesion, and how do design patterns affect them?

    Coupling is how much one module depends on another's details; cohesion is how closely the parts of one module belong together. Good design aims for low coupling and high cohesion, and most patterns…

  18. What is the Prototype pattern, and what is the main pitfall when implementing it?

    Prototype creates new objects by cloning a configured instance. The main pitfall is shallow copying: nested mutable objects (lists, maps, child objects) end up shared between the prototype and its…

  19. What is the Bridge pattern?

    Bridge splits a class that varies in two independent dimensions into two hierarchies, an abstraction (what) and an implementation (how), connected by composition. Message types × delivery channels…

  20. What is the Iterator pattern, and how do modern languages support it?

    Iterator provides sequential access to a collection's items without exposing how it's stored. Modern languages build it into their loops (iter/next, Symbol.iterator, java.util.Iterator, PHP's…

  21. What is the Template Method pattern?

    Template Method defines an algorithm's skeleton in a base class method that calls steps in a fixed order; subclasses implement or override specific steps (abstract steps and optional hooks) without…

  22. What is the Unit of Work pattern?

    Unit of Work tracks objects added, changed or removed during one business operation and commits them all in one transaction, rolling everything back if any part fails. SQLAlchemy's Session, JPA's…

  23. What is CQRS, and how does it relate to the Command pattern?

    CQRS (Command Query Responsibility Segregation) separates the model that changes state (commands like PlaceOrder) from the model that reads it (queries and read models). It borrows the Command idea,…

  24. What is the Middleware (pipeline) pattern used for?

    Middleware handles cross-cutting concerns for many requests or messages (logging, authentication, CORS, rate limiting, error handling, compression, transactions) by wrapping a handler in a chain of…

  25. What is the Flyweight pattern, and when is it worth using?

    Flyweight saves memory when there are huge numbers of similar objects by sharing their heavy, immutable (intrinsic) state and keeping only the small, unique (extrinsic) state per object. It's worth…

  26. What is the Mediator pattern?

    Mediator centralises communication between objects: instead of components referencing and updating each other directly, each talks only to a mediator that holds the coordination rules. A chat room…

  27. What is the Memento pattern?

    Memento captures an object's internal state as an opaque snapshot so it can be restored later, without exposing the object's private fields. The originator creates and restores mementos; a caretaker…

  28. What is the Visitor pattern, and what is its main trade-off?

    Visitor moves operations out of a set of element classes into visitor objects. Each element's accept(visitor) calls the visitor method for its own type (double dispatch). New operations are easy…

  29. What is the Interpreter pattern?

    Interpreter represents a small language's grammar as classes (terminal expressions like variables and numbers, non-terminal expressions like and/or/comparisons) and evaluates a tree of them against…

  30. What is the Null Object pattern, and when can it be harmful?

    A Null Object has the same interface as a real object but neutral behaviour (a guest customer with 0% discount, a NullLogger), removing scattered null checks. It's harmful when absence is actually…

  31. What is the Specification pattern?

    Specification turns a business rule into an object with is_satisfied_by(candidate) that can be combined with and/or/not into larger rules. Rules become named, reusable and testable, and can be…

  32. What is the Object Pool pattern, and where do you meet it?

    An object pool keeps a set of expensive, reusable objects (database connections, threads, buffers) ready for use; callers borrow one and return it instead of creating and destroying objects each…

  33. What is the Strangler Fig pattern, and how do design patterns help with it?

    Strangler Fig replaces a legacy system gradually: new functionality is built alongside it, a routing layer (a facade or proxy) sends some requests to the new code, and the old parts are retired…

Was this page helpful?

Report a mistake