Singleton

 

 

 

Ensure a class only has one instance, and provide a global point of access to it.

Provide a global point of access to the object, generally considered a “Global Variables”. Must be managed carefully, just like global variables. The singleton lets you encapsulate and control the creation process by making sure that certain prerequisites are fulfilled

Pro’s  

Enhanced Security

    Ensuring that no more than a single instance of the class will be created and controlling access to this single instance enhances security.

Reduction of name space pollution 

    Creating a Singleton is essentially equivalent to creating a global variable.  Access to the Singleton can be obtained by any class by calling the Singleton’s instance() method.  For this reason, a reference to the Singleton need not be passed throughout the system.

Con’s

Difficult to extend

    Singletons can be difficult to extend because in order to ensure that only a single instance of the class exists, derived classes may have to ensure that no base class instance has been previously created

 

Back to main page