
On 23/08/2011 07:05, Ben Robinson wrote:
1) Singleton does not give you control over the lifetime of the object. Your implementation, for example, uses a static instance of the object, which is notorious when there are multiple singletons of this type which depend upon each-other. Controlling initialization and teardown order is famously difficult. Singularity does not suffer from these lifetime issues.
It's a function-scope static. The object will be constructed when instance is called for the first time, which is good enough to control initialization order.
2) Singleton forces global access to the class through the ::instance() member. Sometimes this is what you want, other times it is not.
It is trivial to change it to be what you want, including calling special constructors. It's five lines and easily changed to suit whatever needs you may have, which is not the case of a library, even with a policy-based design, which is more restrictive.