intermediateSOLID Principles

What is the Dependency Inversion Principle, and how does it differ from Dependency Injection?

Dependency Inversion is a design PRINCIPLE stating that high-level modules shouldn't depend on low-level modules directly — both should depend on abstractions (interfaces). Dependency Injection is a PATTERN/TECHNIQUE for actually supplying those dependencies (typically via constructor) from the outside rather than a class creating them itself; using DI doesn't automatically guarantee DIP — you can inject a concrete class directly instead of an interface, which still violates the principle even though the dependency is technically 'injected.'

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 is the difference between aggregation and composition?← Back to all Design Patterns & LLD questions