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. What does an IoC container do, and when is it worth using?

    It creates objects, works out their dependencies and injects them for you, often also controlling their lifetime. It saves manual wiring in large applications, but is unnecessary in small ones.

    IntermediateQuick answer1 min read
  2. What is the difference between the Observer pattern and Publish-Subscribe?

    In Observer, observers register directly with the subject and the subject calls them. In Pub-Sub, a message broker sits between publishers and subscribers, so neither knows the other.

    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
  4. What is the difference between a Service Locator and Dependency Injection?

    With DI, dependencies are handed to the class from outside. With a Service Locator, the class asks a global registry for them. The locator hides what the class needs and makes testing harder.

    AdvancedQuick answer1 min read