A2 - Explain Dependency Injection briefly
In order to understand what dependency injection means we need to understand what dependency means
So,
A dependency in programming is an essential functionality, library or piece of code that's essential for a different part of the code to work.
In simple words one part effects some other part.
For example-
Let us assume we write a code where >>
There is a laptop of DELL company
but hard-disk in DELL laptop used belongs to SAMSUNG.
So In simple terms we can say Laptop of DELL is dependent on hard-disk of SAMSUNG.
WHAT IS DEPENDENCY INJECTION ? EXPLAIN...
Dependency Injection (DI) is a design pattern that removes the dependency from the programming code. So that it can be easy to manage and test the application.
Dependency Injection makes our programming code loosely coupled.
LET US CONSIDER THE PREVIOUS EXAMPLE
Let us suppose the company of DELL now wants to change the hard-disk of laptop from SAMSUNG to LENOVO(or any other company).
1- So now we need to change the entire code where SAMSUNG occurs
OR
2- Else we can use DEPENDENCY INJECTION where we can inject LENOVO(or any other company) in place of SAMSUNG.
The second one becomes more convenient if the coding is too long.
Comments
Post a Comment