Interview Q&A / Object-Oriented Programming
Object-Oriented Programming interview questions
The four pillars, interfaces, abstract classes and design basics.
Prefer rapid revision? Practise Object-Oriented Programming short interview answers →
- In the Dependency Inversion Principle, who should own the interface: the high-level or the low-level module?
The high-level module. It declares the interface in terms of what it needs, and low-level modules implement it. That is what inverts the dependency direction.
AdvancedQuick answer1 min read - What rules must an overriding method follow to respect the Liskov Substitution Principle?
It must accept at least what the parent accepts, promise at least what the parent promises, and throw no new kinds of failure. Weaker preconditions, stronger postconditions, same invariants.
AdvancedQuick answer1 min read - Your interface has twelve methods and most implementers leave several empty. How do you fix it without breaking everything?
Introduce smaller role interfaces, make the big interface extend them, move clients to the small ones gradually, then retire the old one. Existing code keeps compiling throughout.
AdvancedQuick answer1 min read