3 ms·
Rearchitecting sure, but when designing a code base from scratch, designing for DI is not a bad approach.
by cema 9y ago
Rearchitecting sure, but when designing a code base from scratch, designing for DI is not a bad approach.
- crdoconnor 9y agoIt can be. I think it's a trade off that needs to be applied on a case by case basis. Too much dependency inversion leads to writing way more code than necessary, all of which needs maintenance. Too little leads to brittle, tightly coupled code. I think you have to weigh up the relative merits of having less code vs. having a lower cost of code change. Furthermore, following YAGNI dictates that you shouldn't really do DI until you actually do need it. I think doing it to facilitate unit testing is a universally bad approach, and a code smell that indicates that what you really wanted was an integration test.