Пример #1
0
        public static SingleObject getInstance()
        {
            if (instance == null)
            {
                instance = new SingleObject();
            }

            return(instance);
        }
Пример #2
0
        static void Main(string[] args)
        {
            //illegal construct
            //Compile Time Error: The constructor SingleObject() is not visible
            // SingleObject object = new SingleObject();

            //Get the only object available
            SingleObject obj = SingleObject.GetInstance();

            //show the message
            obj.ShowMessage("Singleton Pattern Demo...");
        }
Пример #3
0
        static void Main(string[] args)
        {
            SingleObject ob = SingleObject.getInstance();

            ob.setValor("Objeto 1");
            ob.ShowMethod();
            SingleObject ob2 = SingleObject.getInstance();

            ob2.ShowMethod();
            SingleObject ob3 = SingleObject.getInstance();

            ob2.ShowMethod();



            Console.ReadLine();
        }