Google News
logo
Java Springs - Interview Questions
What is Dependency Injection (DI) and Inversion of Control (IoC) ?
In software engineering, Inversion of Control (IoC) is a programming technique in which object coupling is bound at run time by an assembler object and is typically not known at compile time using static analysis.
 
In traditional programming, the business logic flow is determined by objects statically assigned to one another.
 
With inversion of control, the application flow depends on the object graph instantiated by the assembler and is made possible by object interactions defined through abstractions. The binding process is achieved through “dependency injection“.
 
Inversion of control is a design paradigm to give more control to the targeted components of the application, the ones that are actually doing the work.
 
Dependency injection is a pattern used to create instances of objects that other objects rely on without knowing at compile time which class will be used to provide that functionality.
 
Inversion of control relies on dependency injection because a mechanism is needed to activate the components providing the specific functionality. Otherwise, how will the framework know which components to create if it is no longer in control?
 
In Spring, dependency injection may happen in the following ways :
 
* Constructor injection
* Setter injection
* Fields Injection
Advertisement