Oct 10, 2018

[HDGEM] Java Singleton Example

Singleton is a most widely used design pattern.

If a class has and only has one instance at every moment, we call this design as singleton.

class Solution {  public:      /**       * @return: The same instance of this class every time       */      static Solution* getInstance() {          if(obj==null) obj=new Solution();          return obj;      }            private static Solution obj;            private Solution(){      }  };

Posted By Blogger to HDGEM at 3/04/2017 08:04:00 AM