Possible Duplicate:
Understanding the need for a DI framework
I have read several ariticles and talked to several professionals regarding DI. What I Dont understand is the point that how to DI decouples the objects. The following article also describes a scenario but I dont understand how does Spring help in decouplling PayrollApplication? Decoupling is done with polymorphism rather than DI. DI definelty serves some other purpose…
http://www.developer.com/java/dependency-injection-in-existing-java-code.html
Hints and refrences will do. Thanks
Decoupling is not an all-or-nothing concept. In this article using polymorphism only (“Design 2”) decouples the objects to a certain degree, but the PayrollApplication class still has to know about the Employee implementations when PayrollApplication is compiled.
The Employee implementations are the dependencies of PayrollApplication, and with dependency injection you can achieve a higher level of decoupling: you can compile PayrollApplication so that it only references the Employee interface, and supply the Employee implementations (possibly written by another team/organization) only later.
Also check out the Wikipedia about dependency injection: