How does Inversion of Control (IoC) differ from Dependency Inversion (DIP)?

In the literature, there are two different concepts Inversion of control and The principle of inversion of dependencies, which are formulated identically:

  • The modules of the upper levels should not depend on the modules of the lower levels. Both types of modules should depend on abstractions.

  • Abstractions should not depend on details. The details should depend on the abstractions.

What is the difference?

Author: andreycha, 2016-03-03

1 answers

Inversion of Control is a general term that describes the software architecture. It is usually applied to frameworks -- control inversion is one of the characteristics.

Frameworks provide connection points where you can write your code. But the overall execution of the program is still managed by the framework, calling your code from time to time. The inversion is that, unlike the traditional approach, you don't call the library code, but rather the library code calls you. Examples may include ASP.NET and WPF with their events.

At the same time, the principle of inversion of control can also be used on a smaller scale. For example, there is a logic layer (BLL) and data access layer (DAL). It is well known that the DAL cannot access the BLL. But sometimes there is a need at the DAL level to execute some code that should belong to the BLL. In this case, a certain interface is created in the DAL, this interface is implemented at the BLL level, and the instance the specific implementation is passed from the BLL to the DAL. Such an example, in particular, is consistent with DIP.

Dependency Inversion Principle provides recommendations on what dependencies should be. This is exactly what you quoted:

  • The modules of the upper levels should not depend on the modules of the lower levels. Both types of modules should depend on abstractions.
  • Abstractions should not depend on details. The details should depend on the abstractions.

You also you may have heard of Dependency Injection. Dependency injection is the link between IoC and DIP. This is one of the ways implementations of control inversion.


Better read the English Wiki about IoC and DIP, it's much better explained. I think even with the help of Google translate it will be more useful than articles on the Russian Wiki.

As a Russian-language source, I can recommend the article DI vs. DIP vs. IoC from Sergey Teplyakov. Perhaps he will even go into this question and explain everything properly:).

 16
Author: andreycha, 2018-03-10 07:25:09