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.
-
Most asked Explain the SOLID principles.
SOLID is five object-oriented design principles: Single Responsibility (one reason to change), Open/Closed (extend without modifying), Liskov Substitution (subtypes keep the parent's promises),…
-
Most asked Explain the Factory Method pattern and how it differs from a simple factory.
Factory Method lets subclasses decide which product to create by overriding a creation method that a shared algorithm calls. A simple factory is one function or class with a conditional that returns…
-
Most asked Explain the Observer pattern and give examples from real frameworks.
Observer lets a subject notify any number of subscribers when something happens, without knowing what they do. Subscribers register and unregister at runtime. Examples: DOM addEventListener, Node.js…
-
Most asked Explain the Strategy pattern with an example.
Strategy puts interchangeable algorithms behind one interface; a context holds one strategy and delegates to it, so the algorithm can be chosen at runtime without if/else. Shipping cost rules…
-
Most asked Explain the Liskov Substitution Principle with an example.
Subtypes must be usable wherever their parent type is expected, without breaking the parent's promises. The classic violation: Square extends Rectangle, where setting the height also changes the…
-
Explain the Composite pattern with a real-world example.
Composite lets clients treat single objects and groups of objects through one interface. A Folder and a File both implement size(); the folder sums its children's sizes recursively, so callers never…
-
Explain Chain of Responsibility and give a web-development example.
Chain of Responsibility passes a request along a chain of handlers; each one handles it or passes it on. HTTP middleware is the everyday example: auth, rate limiting and validation each can stop the…
-
Is HTTP middleware Chain of Responsibility or Decorator?
Both. Like Chain of Responsibility, each middleware can stop the request (return 401) or pass it on; like Decorator, each wraps the rest of the pipeline with behaviour before and after calling…
-
How do design patterns relate to testability?
Many patterns make code easier to test by putting seams between parts: dependency injection lets tests pass fakes; Strategy, Adapter and Repository let you replace external dependencies with…
-
How is Mediator different from Observer?
Observer broadcasts events from a subject to any subscribers, with no central decision-maker. Mediator is a central object that knows the participants and decides how they interact. Observer…
-
Is it a good idea to name classes after patterns, such as `PaymentStrategy` or `UserFactory`?
Often yes, when the class genuinely plays that role: the name tells readers how it fits the design. It becomes harmful when the name is wrong (a Factory that doesn't create things, an Adapter that's…