Search code examples
dependency-injectionloose-coupling

Are there other benefits to loosely coupled code besides TDD?


When I'm doing TDD, it forces me to employ Dependency Injection principle and I end up with loosely coupled code.

I was told that it's harder to understand application that has loosely coupled code.

Can you tell me what pros and cons of loosely coupled code?


Solution

  • Dependency Injection does not automatically lead to low coupling. I agree with the answers above about the pros of low coupling. The main benefits of Dependency Injection is that it improves testability and that it helps you follow the GoF principle of Program to Interfaces, not Implementations. But you can have high coupling to injected dependencies too.