In the literature there are two different concepts Inversion of Control and the Principle of Inversion of Dependencies , which are formulated equally:

  • 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 the details. Details must depend on abstractions.

What is the difference?

    1 answer 1

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

    The frameworks provide connection points where you can write your code. But at the same time, the overall execution of the program is still controlled by the framework, from time to time calling your code. Inversion is that, unlike the traditional approach, it is not you who call the library code, but the library code that calls you. Examples include ASP.NET and WPF with their events.

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

    Dependency Inversion Principle makes 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 the details. Details must depend on abstractions.

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


    Better read the English wiki about IoC and DIP , everything is much better explained there. I think that even with the help of Google Translate it will be more useful than articles on the Russian Wiki.

    As a Russian-speaking 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 :).

    • and do you not explain on the topic - what are "modules of the upper levels" and "modules of the lower levels", for example, in the context of a web framework? - Goncharov Alexander
    • one
      @GoncharovAleksandr I would say that the modules of the upper levels are modules containing business logic and interface, and the modules of the lower levels are modules containing technical details (for example, accessing a database or a third-party service). By "must not depend on" are meant the details. Those. The business logic module naturally uses the database access module, but at the same time implementation details should not leak into it (for example, what kind of database it is and what index should be used to fulfill the request). - andreycha
    • @GoncharovAleksandr It is necessary to look at the number of a module depending on others. Top-level modules are those that do not depend on anyone and on which other modules depend. The modules of the required level are those that depend on a large number of other modules. - AK