网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

(DesignPattern)Singleton.-创新互联

Role:(DesignPattern)S
ingleton.

The purpose of the Singleton pattern is to ensure that there is only one instance of a class, and that there is a global access point to that object.

创新互联-专业网站定制、快速模板网站建设、高性价比肥乡网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式肥乡网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖肥乡地区。费用合理售后完善,10余年实体公司更值得信赖。

Design:

  • Make the constructor private and add a private static constructor as well.
  • Add a private static read-only object that is internally instantialed using the private constructor.
  • Add a public static property that accesses the private object.

Implementation:

  public sealed class Singleton
    {
// Private constructor.   private Singleton()
        {
            Console.WriteLine("One instance is created."); 
        }

// private object instantiated with private constructor.   private static readonly Singleton instance = new Singleton(); 

// Public static property to get the object.   public static Singleton UniqueInstance
        {
get
            {
return instance; 
            }
        }
    }
  class Program
    {
static void Main(string[] args)
        {
            Singleton s0= Singleton.UniqueInstance;
            Singleton s1= Singleton.UniqueInstance;
            Singleton s2= Singleton.UniqueInstance; 
        }
    }

本文标题:(DesignPattern)Singleton.-创新互联
分享链接:http://bjjierui.cn/article/coephg.html

其他资讯