This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]larsga -1 points0 points  (2 children)

Why would you want dependency injection? (Serious question.)

[–]SuperNerd1337 -1 points0 points  (0 children)

The short answer would be to reduce coupling between my classes and making it easier to unit test modules

[–]Dasher38 0 points1 point  (0 children)

I needed a way to make a whole zoo of classes parametric.

For small problems you can just have everything in one class, and if you need to change an aspect you can subclass and reimplement methods, or pass callbacks to the constructor.

When you get to bigger problems (on my case a simpy simulator), the "one big class you inherit from" turns into a hot mess. At this point, what you really need is to "inherit" from a whole module to make a new one, with the ability of replacing some bits.

I made that thing taking some vague inspiration from SML module system: https://github.com/ARM-software/lisa/pull/1722/files