← All topics

Design Patterns Middle interview questions and answers

75 questions for a Design Patterns (Middle) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.Which pattern was applied in this refactoring?
  2. 2.Why does subscribe in an Observer implementation usually return an unsubscribe function?
  3. 3.How does Decorator differ from Proxy if their structure is similar?
  4. 4.How does Adapter differ from Facade?
  5. 5.When is an Abstract Factory appropriate instead of a simple factory?
  6. 6.What's dangerous about a module-level singleton (export const cache = new Map()) in an SSR app?
  7. 7.How do you implement undo/redo with the Command pattern?
  8. 8.Why are isLoading, isError, isSuccess flags worse than an explicit state?
  9. 9.What's the risk of a global event bus as an implementation of Mediator?
  10. 10.Which pattern do axios interceptors or fetch wrappers implement?
  11. 11.How do you render a comment tree of arbitrary depth?
  12. 12.How does a generator help implement an Iterator for a paginated API?
  13. 13.How does Template Method differ from Strategy?
  14. 14.Why does immutable state simplify the Memento pattern?
  15. 15.Which pattern does a Babel or ESLint plugin use when it walks the AST with Identifier() and CallExpression() methods?
  16. 16.Notifications come in three types and are sent over three channels (email, push, SMS). Which pattern saves you from 9 classes?
  17. 17.Why have a layer of "repositories" or API services on the frontend instead of calling fetch directly in components?
  18. 18.How do you inject a dependency into React components so you can swap the API client in tests?
  19. 19.Which of these situations violates the Liskov Substitution Principle?
  20. 20.A UserCard component takes user: User (30 fields) but uses only the name and avatar. Which principle is violated?
  21. 21.What does the Law of Demeter say about order.customer.address.city.name?
  22. 22.What is unidirectional data flow in the Flux architecture?
  23. 23.How does MVVM differ from React's approach?
  24. 24.Which patterns can you see in Redux?
  25. 25.What is the order of Feature-Sliced Design layers from top to bottom?
  26. 26.Why does every slice in FSD have a public API (index.ts)?
  27. 27.How can barrel files (index.ts re-exporting everything) do harm?
  28. 28.What's the main rule of Clean Architecture?
  29. 29.Where should business rules (e.g. discount calculation) live in a frontend app?
  30. 30.What does Atomic Design describe?
  31. 31.What is shotgun surgery?
  32. 32.What is feature envy?
  33. 33.What is primitive obsession, and how is it treated?
  34. 34.Why do people say "duplication is cheaper than the wrong abstraction"?
  35. 35.What is the Null Object pattern?
  36. 36.How do you implement lazy initialization of a heavy object?
  37. 37.What's wrong with mixins (Object.assign(Class.prototype, mixin))?
  38. 38.What is the Registry pattern, using plugins as an example?
  39. 39.How does a mock differ from a stub in tests?
  40. 40.What is the "test pyramid"?
  41. 41.What is a headless component in terms of patterns?
  42. 42.Which pattern is used in component "slots" (<Card header={...} footer={...}>)?
  43. 43.What is a higher-order function in terms of patterns?
  44. 44.How are event delegation and the Flyweight pattern related?
  45. 45.How is useReducer close to the State pattern?
  46. 46.Which pattern does React.memo or a memoize(fn) function implement?
  47. 47.When should you extract an abstraction, according to the "rule of three"?
  48. 48.Which pattern does the Proxy object in Vue 3 or MobX implement for reactivity?
  49. 49.What is an "anemic model", and why is it criticized?
  50. 50.How does a DI container (Angular, InversifyJS) differ from passing dependencies by hand?
  51. 51.How does Parallel Change (expand/contract) help change a widely used function signature?
  52. 52.What is Branch by Abstraction?
  53. 53.What is the Humble Object pattern?
  54. 54.Why wrap an external payment SDK in your own Gateway?
  55. 55.What problem does Unit of Work solve, e.g. in an editable spreadsheet-like table?
  56. 56.What does the Specification pattern give you for complex filters?
  57. 57.Why add jitter to exponential backoff when retrying requests?
  58. 58.How do you prevent two users from silently overwriting each other's edits of the same record?
  59. 59.What is the Result (Either) pattern for error handling?
  60. 60.How can composition avoid prop drilling without Context?
  61. 61.Why did hooks replace most render props and HOCs?
  62. 62.How are compound components usually implemented in React?
  63. 63.What is a polymorphic as prop?
  64. 64.What is the state reducer pattern?
  65. 65.What are prop getters?
  66. 66.What is the "divergent change" smell?
  67. 67.What is "speculative generality"?
  68. 68.What are data clumps, and how are they fixed?
  69. 69.How do you safely refactor legacy code without tests?
  70. 70.Why do old feature flags become technical debt?
  71. 71.What is a collection pipeline?
  72. 72.What is currying / partial application useful for?
  73. 73.Why is "Adapter" useful when replacing a date library?
  74. 74.Why is the Chain of Responsibility pattern a good fit for validation rules?
  75. 75.Why use the Facade pattern for a complex feature like video upload (chunks, retries, progress)?