Is this a good singleton?
Russel Winder via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Feb 13 23:16:54 PST 2016
On Sat, 2016-02-13 at 18:58 +0000, Vladde Nordholm via Digitalmars-d-
learn wrote:
> Hello. I have this singleton,
>
> ------------------------------------------------------
> class Singleton
> {
> private this() {}
> static __gshared typeof(this) instance = new this;
> }
> ------------------------------------------------------
>
> and I wonder if it has any weaknesses. Or is there a better way
> to make a Singleton?
Following the ACCU consensus: there is never, ever a good Singleton or
reason to contemplate using one.
Obviously though there are some good ones: about dialogues in GUIs for
example.
The good/evil-ness of Singleton is definitely in it's use: most people
use Singleton wrongly, most uses should be banned. Hence the ACCU
consensus.
It's all about coupling and mostly testability of code..
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder at ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: russel at winder.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20160214/2ccfcf09/attachment.sig>
More information about the Digitalmars-d-learn
mailing list