Interview Q&A / Object-Oriented Programming

INTERVIEW Q&A · 69 QUESTIONS

Object-Oriented Programming interview questions

The four pillars, interfaces, abstract classes and design basics.

  1. Show Dependency Inversion with a NotificationService that currently creates EmailSender inside itself.

    Define a Sender interface, have NotificationService depend on it, and pass the implementation in from outside. The service no longer knows whether it is sending email, SMS or WhatsApp.

    BeginnerQuick answer1 min read
  2. What is the difference between Dependency Inversion, Dependency Injection and Inversion of Control?

    DIP is a design rule: depend on abstractions. DI is a technique: pass dependencies in from outside. IoC is the wider idea that a framework or caller controls the flow instead of your code.

    IntermediateQuick answer1 min read
  3. 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