3 ms·
Because code becomes harder to understand. With direct dependencies, if you are trying to understand some code that calls some function and what it does exactl
by Scarblac 7mo ago
Because code becomes harder to understand.
With direct dependencies, if you are trying to understand some code that calls some function and what it does exactly isn't completely obvious, you can press a button to go to it, understand it, and come back.
With dependency injection it depends on what is going to be inserted during runtime, so you can't.
- 9rx 7mo agoIf you can press a button to understand what is going on, "it’s possible to overuse" most definitely applies. Dependency injection, as the name implies, is for dealing with dependencies — things that you cannot observe until runtime. Hence the benefit to testing; allowing you to inject a deterministic implementation while under test.
- Aeolun 7mo agoWith dependency injection your interface always describes what your implementation can do. If you see the interface and you have to care what is going to happen when you use it you are doing it wrong.