Wednesday, March 2, 2016

[Design Pattern] Singleton

Java

class SingleControlor{
         private static SingleControlor  instance= null;
       
         public static getSingleInstance(){
                    if(null == instance) {
                                instance = new SingleControlor();
                    }
                    return instance;
         }

         private SingleControlor(){}
}

C++

class SingleControlor{
public:
           static SingleControlor getInstance(){
                       if(_instance == NULL){
                                    _instance = new SingleControlor(); 
                       }
           }
private:
           SingleControlor(){};
           static SingleControlor* _instance = null;
}

No comments:

Post a Comment