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