Ygor Serpa
1 min readSep 13, 2020

--

I am not sure you got my point. Treat singletons as a concept for a minute, forget about how they are written and called. What they are is a single global access point to a functionality. That's essentially the same as a service, the sole difference is how you access it (url vs call). The same goes for the OS. Malloc and free are global access points to a functionality (memory) that's unique to the whole system.

Indeed, the way singletons are >typically< implemented disallows us to mock them or do dependency injection, true. However, the idea stretches far beyond having a static object and a private constructor.

In fact, many DI engines support singletons, the difference lies that they are provided to entities instead of exposed statically. Singletons nonetheless.

--

--

Ygor Serpa
Ygor Serpa

Written by Ygor Serpa

Former game developer turned data scientist after falling in love with AI and all its branches.

No responses yet