Monday, May 31, 2010

Singleton Design Pattern

namespace Organization
{
    class Employee
    {
        // Cretae a static object of the class 
        private static Employee _employee = null;
     
       // This method will  be called, whenever an instance of the class will be needed
        public static Employee GetInstance()
        {
            if (_employee == null)
            {
                _employee = new Employee();
            }
            return _employee;
        }

       // Default constructor is specified as private so that it could not be used from outside
        private Employee()
        {
        }
    }
}

No comments:

Post a Comment