Possible Duplicate:
How exactly does dependency injection reduce coupling?
Dependency Injection as a concept, I think, encapsulates loose coupling. Is it correct to say that it helps in achieving Loose Coupling? From what I understand, if you have designed a class with loose coupling, then you can implement DI on it. Please help me understand and correct me if I am wrong.
I would say that loose coupling has inherently nothing to do with DI. You can use DI on a project that has completely tight coupling if you want.
Loose coupling is isolation of one component from the implementation details of another. It is typically achieved in java by providing collaborators as an instance of an interface, rather than a concrete class.
What i would say is that DI tends to lead people toward loosely coupled code in many situations, but it doesn’t force them to it (though in some products like spring there are a lot of downsides to not using interfaces). Containers also have support for wiring loosely coupled collaborators as well. This example is perfectly fine in a DI container, while being tightly coupled.
However, this is loosely coupled, since the “SomeOtherService” is tied to the interface.
Insert your favorite wiring mechanism (guice, spring annotations, spring xml, java cdi), but the concept is the same.
Wikipedia has a good article on loose coupling:
http://en.wikipedia.org/wiki/Loose_coupling