Hacker News new | ask | show | jobs
by timclark 391 days ago
The D in SOLID is for dependency INVERSION not injection.

Most dependency injection that I see in the wild completely misses this distinction. Inversion can promote good engineering practices, injection can be used to help with the inversion, but you don’t need to use it.

4 comments

Moreover, dependency inversion is explicitly not about construction, which conversely is exactly what dependency injection is about.
Agreed, and I conflated the two since I've been describing SOLID in ways other devs in my team would understand for years.

Liskov substitution for example is an overkill way of saying don't create an implementation that throws an UnsupportedOperationException, instead break the interfaces up (Interface Segregation "I" in SOLID) and use the interface you need.

Quoting the theory to junior devs instead just makes their eyes roll :D

LSP is about much more than not throwing UnsupportedOperationException, that’s a complete mischaracterization.

ISP isn’t about avoiding UnsupportedOperationException as well, it’s about reducing dependencies.

In Java land this is really the closest analogy I could create an example for. Do you have better example I could use with Java pls?
Honestly inversion kinda sucks because everybody does it wrong. Inversion only makes sense if you also create adapters, and it only makes sense to create adapters if you want to abstract away some code you don’t own. If you own all the code (ie layered code), dependency inversion is nonsensical. Dependency injection is great in this case but not inversion.