依赖倒置原则
Dependence Inversion Principle , DIP
High level modules should not depend upon low level modules.Both should depend upon abstractions.
Abstractions should not depend upon details. Details should depend upon abstractions.
三层含义:
- 高层模块不应该依赖低层模块,两者都应该依赖其抽象。
- 抽象不应该依赖其细节。
- 细节应该依赖抽象。
依赖倒置原则在java语言中的表现就是:
- 模块间的依赖通过抽象产生,实现类之间不发生直接的依赖关系,其依赖关系是通过接口或抽象产生的。
- 接口或抽象类不依赖于实现类;
- 实现类依赖接口或抽象类。
浙公网安备 33010602011771号