Paranoidal Singleton

added by ksh2dotnetkicks
2/21/2010 5:53:14 PM


1 - If one object must have at most one instance in an application, then no one must be able to capture a pointer to it in any other scope. In other word's it should have at most one pointer to it in whole application, too. Otherwise it's lifetime and service access can not be controlled. So there must be a proxy to that object and at any time, just one of these proxies has access to the actual instance. 2 - In Singleton pattern, if the single instance object have any kind of changing states then it will become a source of disaster (as any other global state in the application). So it is not just enough to provide a thread-safe pointer access. Instead we need a working scope for our singleton object. Using proxy pattern we can achieve this goal: at anytime there is just one pointer to singleton and there is just one user for it.