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