Boost logo

Boost :

Subject: Re: [boost] Review Request: Singularity
From: Ben Robinson (icaretaker_at_[hidden])
Date: 2011-08-24 16:15:31


>
> 2) The instance() member is global, so you cannot fully encapsulate it
>> inside the classes that need it. Singularity allows you to optionally
>> expose global access to the class, should you desire context independent
>> objects.
>>
>
> The code is two lines of straightforward C++. You're free to encapsulate it
> the way you want. That's easier than dealing with the idiosyncrasies of a
> library.
>
> Creating a Singleton instance with the global instance() member and passing
the resulting object into another object for encapulation, does not
encapsulate the Singleton. The instance() member is still global, and any
other code, can directly access that instance. Therefore, Singleton exposes
the instance at global scope, prevent true encapsulation.

Sometimes global access is desirable. However, sometimes we use Singleton
just to enforce the single instance, and get the global access as baggage.
 Instance count and accessibility should be orthogonal. Singularity allows
you to enforce the single instance, and <optionally> provide global access
to the instance, according to the developer's needs.

Ben Robinson, Ph.D.

______________________________**_________________
> Unsubscribe & other changes: http://lists.boost.org/**
> mailman/listinfo.cgi/boost<http://lists.boost.org/mailman/listinfo.cgi/boost>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk