intermediateDependency Inversion Principle

What's the difference between Dependency Inversion and Dependency Injection?

Dependency Inversion is a design principle: high-level modules and low-level modules should both depend on a shared abstraction, rather than the high-level module depending directly on the low-level module's concrete details. Dependency Injection is a technique for supplying an object's dependencies from outside — typically through a constructor, setter, or framework — instead of the object constructing them internally itself. The two are related but not interchangeable: you can inject a dependency through a constructor and still violate Dependency Inversion, if the constructor parameter is typed as a concrete class rather than an interface, since the coupling has simply moved rather than actually being removed. Genuine Dependency Inversion requires both pieces together — an abstraction for both sides to depend on, and some mechanism, usually injection, for supplying the concrete implementation from outside.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What does it mean for a class to be 'open for extension but closed for modification'?← Back to all Low-Level Design & Design Patterns questions