The difference between "control inversion", "dependency inversion" and "decoupling"

I read the theory of dependency inversion and decoupling, and I don't see the difference between the two.

Dependency inversion indicates the decoupling of functional components, so that higher-level components are independent of lower-level components.

The denouement speaks of the same thing and how to achieve it. But then we have IoC containers that mess things up even more. Why aren't they rather called dependency inversion containers or even better dependency injection containers because they serve temporary connections of independent components?

Then we have Inversion of control . This is basically the same as dependency inversion, is it? Why are there three terms that describe the same thing? Or am I blind?

  • What is the difference between the three?
  • What should IoC do in IoC containers?
+52
dependency-injection ioc-container decoupling
Oct 12 '10 at 7:41
source share
4 answers

Interchange is a very general principle applicable in many areas. Dependency inversion is a special form of decoupling where you separate the higher levels of your system from the lower levels, dividing them into libraries and using interfaces. This allows you to replace parts of the lower level of your system without major rework.

For example, instead of parts of a higher level system that create specific instances of lower level classes, an IoC container can be used to decouple objects created.

Inversion of control is a design principle used by framework libraries that allow the framework to regain some control over the application. Ie, the window infrastructure can return to application code when certain user interface events occur. Martin Fowler uses the term โ€œHollywood principle,โ€ as in โ€œDon't Call Us,โ€ we'll call you. Decoupling is an important part of control inversion.

But what does an IoC container have for inversion of control? To quote Martin Fowler :

Management inversion is too general a term, and therefore people find it confusing. As a result, with a lot of discussion with various IoC advocates, we settled on the name Dependency Injection.

(Note that Martin Fowler talks about dependency injection, not dependency inversion.)

An IoC container helps inject dependency injection, and perhaps the best term would be a dependency injection container. However, the IoC container name seems to adhere. Dependency injection is an important component of dependency inversion, but the use of IoC containers for dependency injection can be confusing because management inversion is a broader and more general principle.

You indicate that the naming is not very consistent, but this should not be a big surprise, as these terms were independently invented and used, although they overlap.

+59
Oct 12 '10 at 7:59
source share

Dependency Injection achieves Decoupling using Inversion Control .

+43
Oct 12 2018-10-10T00:
source share

I find the following explanation from the DIP in the Wild article on martinfowler.com for understanding (here DI = Dependency Injection, DIP = Dependency Inversion Principle, IoC = Control Inversion):

DI is how one object gets a dependency. When a dependency is provided that the system uses DI. IoC is who initiates the call. If your code initiates a call, it is not an IoC, if the container / system / library accesses the code you provided it is an IoC.

DIP, on the other hand, refers to the level of abstraction in messages sent from your code to the subject that it calls. (...) DI is about wiring, IoC is the direction, and DIP is the form [of the object the code depends on.)

+15
Aug 25 '16 at 9:10
source share

Dependency Inversion: Depends on abstractions, not nodules.

Inversion of control: the main thing against abstraction and how the main thing is the glue of the systems.

DIP and IoC

Here are some good posts about this:

https://coderstower.com/2019/03/26/dependency-inversion-why-you-shouldnt-avoid-it/

https://coderstower.com/2019/04/02/main-and-abstraction-the-decoupled-peers/

https://coderstower.com/2019/04/09/inversion-of-control-putting-all-together/

0
Apr 13 '19 at 14:52
source share



All Articles