Depend upon abstraction. Code to interfaces and not to concrete implementations.
This is similar to the OO principle: "program to an interface and not to an implementation". However, the DIP makes an even stronger statement about abstraction. It means any component (high or low level) within an application should depend upon abstractions. A high level component is one whose behavior is defined in terms of other lower level components.
The following guidelines help in avoiding OO designs that violate the DIP:
- No variable should hold a reference to a concrete class. Do not use new, use factories.
- Do not derive from concrete classes. Derive from abstract or interfaces. If your are deriving from concrete classes then there is a dependence on the concrete class.
- Do not override base class methods. Those concrete methods in the base class are meant to be shared between all the derived classes.
Inverson of control:
This generic term is also synonymous with Dependency Injection.
The assembler injects the dependency and reduces tight coupling between classes.