⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 singletonstructural.cs

📁 使用C#程序将23个常用设计模式进行列表显示
💻 CS
字号:
using System;
using System.Collections;
using System.Windows.Forms;

namespace DesignPattern.SingletonStructural
{
    class SingletonStructural : AbstractPattern
    {
        public static void Run(TextBox tbInfo)
        {
            s_tbInfo = tbInfo;
            s_tbInfo.Text = "";

            //base.Run(tbInfo);
            // Constructor is protected -- cannot use new 
            Singleton s1 = Singleton.Instance();
            Singleton s2 = Singleton.Instance(); 
            if (s1 == s2) 
            {
                DesignPattern.FormMain.OutputInfo("Objects are the same instance");
                //DesignPattern.FormMain.OutputInfo("Objects are the same instance"); 
            } 
            // Wait for user 
            ////Console.Read();
        }
    }

    class Singleton 
    {
        private static Singleton instance; 
        // Note: Constructor is 'protected' 
        protected Singleton() 
        {
        }
        public static Singleton Instance()
        {
            // Use 'Lazy initialization' 
            if (instance == null) 
            {
                instance = new Singleton(); 
            }
            return instance; 
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -