3 ms·
It's not just about testing. When any code constructs its own object, and that object is actually an abstraction of which we have many implementations, that cod
by kazinator 1y ago
It's not just about testing. When any code constructs its own object, and that object is actually an abstraction of which we have many implementations, that code becomes stupidly inflexible.
For instance, some code which prints stuff, but doesn't take the output stream as a parameter, instead hard-coding to a standard output stream.
That leaves fewer options for testing also, as a secondary problem.
- layer8 1y agoThat’s just parameterization, though. It’s overkill to call every parameter (or even most parameters) a “dependency”.
- kazinator 1y agoSo even "dependency parametrization" would be better than "injection". Since what we want to parametrize are objects held by composition, maybe "composition parametrization". "To promote better flexibility and code reuse and to make testing easier, parametrize object composition."