Does Dependency Injection help us achieve Loose-Coupling? [duplicate]-Collection of common programming errors

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.

public class FooService { ... }

public class SomeOtherService {
     public SomeOtherService(FooService fooService) {
          this.fooService = fooService;
     }
}

However, this is loosely coupled, since the “SomeOtherService” is tied to the interface.

public interface FooService { ... }

public class SomeOtherService {
     public SomeOtherService(FooService fooService) {
          this.fooService = fooService;
     }
}

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