3 ms·
Dependency injection should pretty much be renamed: "Unit testing in java". Sure you can come up with contrived examples like: Algorithm swapping, or integrati
by 1stop 12y ago
Dependency injection should pretty much be renamed: "Unit testing in java". Sure you can come up with contrived examples like: Algorithm swapping, or integration point swapping, but I would hazard a guess that covers about 1% of DI code written, the other 99% is for unit testing.
You can achieve weak dependencies, easy refactoring and bad design without DI (Maybe it's harder in java to do thought :\ ).
The magic question of DI is, how do you decide what is a dependency worth injecting vs a static/strong dependency? In my experience its: "Inject everything". Which leads convoluted code. The correct answer (imo) is "you can't, unless you can predict the future".