I have been here. It can be really painful. Personally this is why I don't follow the pattern of injecting interfaces unless there is a good reason to do so. If you inject actual implementations it greatly simplifies figuring out what is coming from where. You can still inject mocks for testing so it is just as smooth.
And let's be honest: in 99% of the cases you don't need interfaces anyway. Most code is de facto tightly coupled and/or will never be changed anyway.
We have several projects where the devs made sure everything implements an interface, but almost none of these actually ever changed some implementation in the background. So why bother making your code harder to read, just for the slight advantage of not having to extract an interface maybe 20 years from now?
I am not sure where this pattern comes from but it is pervasive. The benefits have always seemed dubious to me. If you are writing a framework, sure go nuts, but if you are writing an application that wants to test and verify everything works you don't want implementations swapping in and out.
As far as I can tell, this comes from the "reusability is everything" hype.
Every component has to be written in a way that abstracts away any coupling to anything, in case you might want to reuse that class. And in the end you write 300 lines of code to maybe save 5 lines at some point. To me this looks like the typical take one principle and overshoot it's application to the max.
3
u/deadron Apr 21 '21
I have been here. It can be really painful. Personally this is why I don't follow the pattern of injecting interfaces unless there is a good reason to do so. If you inject actual implementations it greatly simplifies figuring out what is coming from where. You can still inject mocks for testing so it is just as smooth.