4、依赖倒置原则(Dependency Inversion Principle, DIP)
定义
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.
- 高层模块不应该依赖于低层模块,两者都应该依赖于抽象。
- 抽象不应该依赖于细节。细节应该依赖于抽象。
简而言之就是“面向接口编程”。