Dependency Inversion Principle
Updated 2026-07-30
Summary
In object-oriented design, the dependency inversion principle is a specific methodology for loosely coupled software modules. When following this principle, the conventional dependency relationships established from high-level, policy-setting modules to low-level, dependency modules are reversed, th…
Definition
High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions. Scaffold use: decouple core logic. The CEO (high-level) should not depend on a specific secretary (low-level), but on the 'secretary job responsibilities' (abstraction). This way, even if the secretary changes, the CEO's workflow is not interrupted.
Introduction
How to use
Decouple core logic. The CEO (high-level) should not depend on a specific secretary (low-level), but on the 'secretary job responsibilities' (abstraction). This way, even if the secretary changes, the CEO's workflow is not interrupted.
Mechanism
The 'D' in SOLID. Both high-level policy modules and low-level implementation modules depend only on abstract interfaces, not on each other's concrete classes. This way, changing the implementation (low-level) does not affect high-level logic. The high-level defines the interface, and the low-level adapts to it, achieving decoupling and replaceability. The essence is 'programming to interfaces'.
Practice
In progress 0/5Practice this model in one real situation:
Cases
- Business layer depends on 'storage interface' rather than a specific MySQL class; changing database only requires changing implementation; notification module depends on 'message sending interface', with SMS/email each implementing it; CEO depends on 'secretary responsibilities' abstraction rather than a specific person.
Common pitfalls
- Thinking that 'moving new elsewhere' is DIP (just transferring dependency); misplacing abstraction definition (abstraction owned by low-level causes reverse coupling); over-abstraction leading to interface explosion.
Sources
Source support: Explicit
References currently contain only Wikipedia links; primary sources still need review.
- en.wikipedia.orghttps://en.wikipedia.org/wiki/Dependency_inversion_principleverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS