Thursday, September 19, 2013

SingleTon

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


    public class Singleton
    {
        private static Singleton uniqueInstance;
        //other useful instance variables here

        private Singleton()
        {

        }

        public static Singleton getInstance()
        {
            if (uniqueInstance == null)
            {
                uniqueInstance = new Singleton();
            }
            return uniqueInstance;
        }
        //other useful methods here
    }



Where it can be used?
Printer 
For logging
Holding Registry entry in single object.

No comments:

Post a Comment

Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code