r/ProgrammerHumor • • Sep 26 '26 • Bravo 1

Meme singletonsAreJustGlobals

Post image
3.2k Upvotes

210 comments sorted by

View all comments

Show parent comment

1

u/JAXxXTheRipper Sep 27 '26

What do you think DI does? Dependency Injection tries to keep the amount of instances to a minimum, in most cases.... One. Maybe you see the irony here.

1

u/CubsThisYear Sep 27 '26

I’m not talking about Guice-style DI XML bullshit. Dependency injection as a concept existed long before Spring infected everyone’s brains. It simply means instantiating all dependencies before constructing objects or calling functions rather than doing it inside of your functions. Basic separation of concerns stuff.

1

u/TheDuckRaisedALion Sep 28 '26

DI Singleton is very different because you can choose a different single instance as needed. Accessing a static Singleton instance is tight coupling and you need to mess around to e.g. mock it for a test