Difference between dependency injection and dependency inversion?
The point
These are different things with similar names:
- Dependency Inversion Principle (DIP) — a design principle (the D in SOLID): a high-level module does not depend on a low-level one, both depend on an abstraction, and the high level owns that abstraction. It is about the direction of dependencies in the type graph.
- Dependency Injection (DI) — a technique: an object receives its dependencies from outside (through
init, a property or a method parameter) instead of creating them itself. It is about the way a dependency is handed over.
DI is the most common way to implement DIP, but each can exist without the other.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep