I'm currently studying Spring and suddenly, I've got curious about DI
And my question is What're the main reasons to use DI?
Sorry for Duplicate Question..
I'm currently studying Spring and suddenly, I've got curious about DI
And my question is What're the main reasons to use DI?
Sorry for Duplicate Question..
DI is automated, configurable way of instantiating graph of objects. From Spring in Action, Craig Walls, Ryan Breidenbach:
Any nontrivial application is made up of two or more classes that collaborate with each other to perform some business logic. Traditionally, each object is responsible for obtaining its own references to the objects it collaborates with (its dependencies). When applying DI, the objects are given their dependencies at creation time by some external entity that coordinates each object in the system. In other words, dependencies are injected into objects.
You may read answers on question :"What is dependency injection?". That way you'll get clearer picture, what are the main reasons to use it.
And maybe take a look at that great article.