Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 732
Vadim Avatar asked Dec 04 '22 15:12

Vadim


2 Answers

The biggest advantage is that introducing changes to one module does not break other modules in unpredictable ways.

like image 102
Manu Avatar answered Jan 13 '23 00:01

Manu


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.

like image 29
solsson Avatar answered Jan 12 '23 23:01

solsson