Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Inversion of Control & Dependency Injection [duplicate]

IoC and DI concept were very much confusing for me so I read lots of views and post of different people and finally reach to the conclusion. So as I understand these topics are...

Inversion of control is a technique in java for making loosely coupled and more easily maintainable applications, and dependency injection is a one of the way to achieve this concept(technique).

Inversion of control container inject dependency at run time from java classes to make loosely coupled application.

Is this true ? correct me if I am wrong...

like image 360
Devendra Anchal Avatar asked Nov 12 '14 10:11

Devendra Anchal


People also ask

What is Inversion of Control?

Inversion of control is a software design principle that asserts a program can benefit in terms of pluggability, testability, usability and loose coupling if the management of an application's flow is transferred to a different part of the application.

Is Inversion of Control and Dependency Inversion the same?

Inversion of Control Although it's often confused with the DIP, IoC is different in that it is a programming technique that allows run-time object coupling binding to occur by a framework where the binding is otherwise not known at compile time using static analysis.

Why it is called Inversion of Control?

Dependency Injection was originally called Inversion of Control (IoC) because the normal control sequence would be the object finds the objects it depends on by itself and then calls them. Here, this is reversed: The dependencies are handed to the object when it's created.

What is the difference between dependency inversion and Dependency Injection?

The Inversion of Control is a fundamental principle used by frameworks to invert the responsibilities of flow control in an application, while Dependency Injection is the pattern used to provide dependencies to an application's class.


1 Answers

IoC is a generic term meaning rather than having the application call the methods in a framework, the framework calls implementations provided by the application.

DI is a form of IoC, where implementations are passed into an object through constructors/setters/service look-ups, which the object will 'depend' on in order to behave correctly.

Reference : Inversion of Control vs Dependency Injection

like image 164
NG. Avatar answered Sep 20 '22 10:09

NG.