コード例 #1
0
        public static SingleObject getInstance()
        {
            if (instance == null)
            {
                instance = new SingleObject();
            }

            return(instance);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: sinhdev/ooad
        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();
        }