Dependency Injection - Design of Computer Programs

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

No, dependency injection is when you INJECT the dependency - as in, perform compile-time trickery to replace "random" with something else WITHOUT changing the function. It's not injection if the function knows about it and has been specifically designed and coded to allow such substitution.

If Python doesn't support dependency injection, then I guess you have to do it this way, but it's not dependency injection unless the function remains unaware of what's going on.

SodAlmighty
Автор

Which means, additionally, that I have wasted two and a half minutes of my life watching a video informing me that it's possible to pass random number generators into a function. Which everyone who's ever tried to write a unit test knows, because when you use unit tests, you have to pollute your codebase with such nonsense.

The whole point of unit tests is to be able to test a function that doesn't know it's being tested. You shouldn't have to design the function to be "testable".

SodAlmighty