mediumConceptDesignMidSenior
What is the dependency inversion principle, and what exactly is being inverted?
3 min readUpdated 2026-08-15
Answer
Short answer
High-level policy should not depend on low-level detail; both should depend on an abstraction. What inverts is ownership of the interface - it belongs to the module that consumes it, not to the one that implements it, which is what reverses the direction of the source dependency.
Was this answer helpful?
Likely follow-ups
- You have one implementation and no plans for a second. Is the interface still justified?
- Where should the interface file physically live, and why does that matter?
- How is this different from dependency injection?
- Your repository interface returns a database-specific cursor type. What has gone wrong?
Related questions
- Give me a real single-responsibility violation you have seen, and how would you refactor it?mediumAlso on solid5 min
- How would you implement a singleton, and why do many teams treat it as an anti-pattern?mediumAlso on testability4 min
- What are the four pillars of OOP, and what is the difference between abstraction and encapsulation?easyAlso on abstraction5 min
- The business insists on a requirement that nobody can test — "the system must be intuitive". What do you write instead?mediumAlso on testability4 min