Dependency inversion refers to a specific form of decoupling software modules. The principle is that high level modules and low level modules should depend on abstractions, and abstractions shall not depend on implementation details. Not to be confused with dependency injection which is a special form of dependency inversion.

What is it ?

Dependency inversion refers to a specific form of decoupling software modules. The principle is that high level modules and low level modules should depend on abstractions, and abstractions shall not depend on implementation details.

It reverses the more conventional and intuitive approach in object oriented programming of having high level modules are build on top of low level modules which they then depend on.

How is it implemented ?

Dependency inversion can be implemented in several ways, the most common ones being:

  • : the interface of an object refers to an abstraction, and the concrete implementation of that abstraction is provided at run time.
  • : an object depends on an abstraction, and the concrete implementation of that abstraction is obtained via an intermediary

More infos:

Disambiguation:

  • avoid the confusion with dependency injection, which is a special form of dependency inversion and has the same DI abreviation.
  • avoid the confusion with inversion of control, which may use dependency inversion, but is about a different concern