Hacker News new | ask | show | jobs
by ActorNightly 1546 days ago
While you are correct that DI is very good in java, DI is needed because of heavy reliance on OOP (i.e, in order to create an instance of an object, you have to lock in functionality with a dependency before you can run that functionality).

If you use a language that doesn't require OOP, you can do the same isolated unit tests without DI.

1 comments

I want to expand on what you said: It's more than just OOP, or not necessarily OOP in general that needs this type of DI and IOC.

It's a specific category of OO architecture, where effects and state are buried under domain logic and information processing (via DI). If you keep that part data oriented and pragmatically functional, then you get a very testable core. Meaning no mocks, stubbing setup/tear-down (...) are required. No additional interfaces have to be specified that you didn't need in the first place. Tests are way simpler this way.

You can still use objects, interfaces and composition etc. for domain logic and information processing if you want. Point is you lift state and effects up, so this stuff happens at the edge of your program that calls into a simpler core.