OOP & SOLID Senior interview questions and answers
75 questions for a OOP & SOLID (Senior) interview - with correct answers, explanations and links to the docs.
- 1.Liskov and Wing define subtyping behaviorally. What does that add beyond matching method signatures?
- 2.Why are Java arrays covariant a design flaw?
- 3.What does PECS mean for Java generics?
- 4.Why must method parameter types be contravariant for a safe override?
- 5.Why does TypeScript accept this override even with
strictFunctionTypeson? - 6.What is the expression problem?
- 7.How does the Visitor pattern shift the expression problem trade-off?
- 8.What problem does double dispatch solve?
- 9.Which overload runs in Java, and why?
- 10.How do Java 21 pattern matching and sealed types change the Visitor trade-off?
- 11.What does a virtual method table (vtable) do?
- 12.Why can megamorphic call sites be slower in JIT-compiled languages like Java or JavaScript?
- 13.What is the yo-yo problem?
- 14.Why is "open recursion" (
thiscalls dispatched to subclasses) the root of the fragile base class problem? - 15.What is the Parallel Inheritance Hierarchies smell?
- 16.What is a DDD aggregate?
- 17.Why do DDD guidelines recommend referencing other aggregates by ID rather than by object?
- 18.What is a common rule about transactions and aggregates?
- 19.How should
equals()andhashCode()work for a JPA entity with a database-generated ID? - 20.Why can ORM lazy-loading proxies surprise OOP code?
- 21.What is the object-relational impedance mismatch?
- 22.What does the Stable Dependencies Principle say?
- 23.What does the Stable Abstractions Principle add to that?
- 24.What does the Common Closure Principle say?
- 25.What is connascence?
- 26.
createUser("Ann", "ann@x.io", true, false, 3)has which kind of strong connascence? - 27.What is a captive dependency in a DI container?
- 28.Why is a Service Locator considered worse than constructor injection by many authors?
- 29.What is temporal coupling in a class API?
- 30.How does hexagonal architecture (ports and adapters) apply DIP?
- 31.What is a seam, in the sense of working with legacy code?
- 32.What is the Humble Object pattern?
- 33.Why are immutable objects safe to share between threads without locks in Java?
- 34.What breaks the safety of
finalfields in an immutable Java class? - 35.Why do persistent data structures make immutability practical for large collections?
- 36.Alan Kay, who coined "object-oriented", stressed which idea most?
- 37."Objects are a poor man's closures, closures are a poor man's objects." What does it mean?
- 38.How do TypeScript branded types help when structural typing is too permissive?
- 39.What does type erasure in Java generics mean for OOP design?
- 40.Which critique of SOLID is most fair?
- 41.How do the SOLID principles map to functional programming?
- 42.Why is Information Expert sometimes in tension with SRP?
- 43.When is an anemic model with transaction scripts a reasonable choice?
- 44.How does Tell, Don't Ask relate to read-heavy screens and CQRS?
- 45.What does the Liskov principle imply for a cache decorator around a repository?
- 46.Why is "is-a" in the real world a poor test for using inheritance?
- 47.What risk comes with a shared
commonorcorelibrary used by every service? - 48.Why can the same concept, like
Customer, have different models in different bounded contexts? - 49.What is a domain event in OOP terms?
- 50.Which approach best replaces a deep
Employeehierarchy where roles change at runtime? - 51.How can you break up a God class safely in a production system?
- 52.What is the Strangler Fig approach in the context of OO refactoring?
- 53.Why are getters on value objects less of a problem than on entities?
- 54.What is wrong with this "immutable" class?
- 55.Interface Segregation at a service boundary often leads to what?
- 56.How do OCP and sealed, exhaustive hierarchies relate?
- 57.What is the main design risk of reflection-based frameworks that set private fields?
- 58.What does encapsulation have to do with team boundaries (Conway's law)?
- 59.Why do React hooks illustrate "composition over inheritance"?
- 60.What does Python's
__init_subclass__or a metaclass let a base class do, and what's the risk? - 61.What is the risk of a deep hierarchy of abstract base classes in a framework?
- 62.How does DIP enable a plugin architecture?
- 63.Why can a
ResultorEithertype be better than exceptions for domain errors in OO code? - 64.What does "make illegal states unrepresentable" mean for class design?
- 65.What is an Identity Map?
- 66.Why might you prefer an abstract class over an interface for a public library API?
- 67.What is the main idea of "functional core, imperative shell"?
- 68.Why can overusing interfaces with one implementation hurt navigation and design?
- 69.In a dynamically typed language, how is LSP usually enforced?
- 70.Why is mutable shared state the main enemy of both concurrency and local reasoning?
- 71.What does the Acyclic Dependencies Principle require, and how is a cycle usually broken?
- 72.What is a key difference between C++ and Java in how methods dispatch by default?
- 73.A team wants to share behavior between
InvoiceandQuoteby extending aDocumentbase class. What question decides whether that's right? - 74.Why is a mutable global singleton especially harmful for testability?
- 75.What does Martin Fowler's Aliasing Bug describe?