Program size, linking matter, and static this()

so so at so.so
Sat Dec 17 13:02:56 PST 2011


On Sat, 17 Dec 2011 21:20:33 +0200, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:

> On 12/17/11 6:34 AM, so wrote:
>> If you are using singleton in your C++/D (or any other M-P language)
>> code, do yourself a favor and trash that book you learned it from.
>>
>> ---
>> class A {
>> static A make();
>> }
>>
>> class B;
>> B makeB();
>> ---
>>
>> What A.make can do makeB can not? (Other than creating objects of two
>> different types :P )
>
> Singleton has two benefits. One, you can't accidentally create more than  
> one instance. The second, which is often overlooked, is that you still  
> benefit of polymorphism (as opposed to making its state global).
>
> Andrei

Now i am puzzled,
"makeB" does both and does better. (better as it doesn't expose any detail  
to user)


More information about the Digitalmars-d mailing list