Interview Q&A / Object-Oriented Programming

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is the difference between Dependency Inversion, Dependency Injection and Inversion of Control?

SHORT ANSWER

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.

Explain it simply

A company's HR policy says "hire through the standard job description, not by naming a person" (DIP). The HR team hands each department its new hire instead of departments picking their own (DI). And the manager does not call you; HR calls you for the interview slot, which is the Hollywood principle, "do not call us, we will call you" (IoC).

DIP is the goal, DI is one way to reach it, and IoC containers such as Spring automate DI.

Example

java
interface MessageSender { void send(String msg); }       // abstraction (DIP)

class Alert {
    private final MessageSender sender;
    Alert(MessageSender sender) { this.sender = sender; } // injected (DI)
    void raise() { sender.send("Server down"); }
}

// Someone else decides which implementation to use (IoC)
new Alert(new SmsSender()).raise();
new Alert(new EmailSender()).raise();

You can follow DIP and DI by hand with no framework. A framework adds IoC on top.

What to say in the interview

"DIP says high-level code should depend on abstractions, not concrete classes. DI is passing the concrete object in from outside, such as through a constructor. IoC is the broader flip where a container or framework creates and wires objects and calls your code."

Common mistakes

  • Using the three terms as synonyms.

#solid#dip#dependency-injection

Related questions

Practise more Object-Oriented Programming questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Object-Oriented Programming quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.