Singleton in Action?

Ron Tarrant rontarrant at gmail.com
Mon Feb 4 10:21:18 UTC 2019


On Sunday, 3 February 2019 at 15:33:15 UTC, Russel Winder wrote:

> There is a lot of good stuff (both positive and negative) on 
> Singleton here, but there is also a bit of prejudice and 
> bigotry. Many of the links are worth looking through.
>
> https://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons

Thanks, Russell. I'll take a look.

> The good use case for Singleton is very rare, most people use 
> them wrongly. It is all about eschewing all global state except 
> when it is the one and only way of doing the design correctly. 
> But then you have to use it correctly.

Yup. I've gone back and forth on usage, too. The cases I found 
for a Singleton ten years ago may have better solutions today. 
Like a command dispatcher, a configuration changes tracker, a 
keyboard pre-processor, an undo/redo stack, and the application 
itself.

> I currently have two Singletons in all my code, one I am trying 
> to get rid of, the other is fair enough. I think, but I'd still 
> like to get rid of it.

I'd be curious to hear what you have/will replace a singleton 
with.


More information about the Digitalmars-d-learn mailing list