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.
Design:
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;
}
}
當(dāng)前題目:(DesignPattern)Singleton.-創(chuàng)新互聯(lián)
本文鏈接:http://jinyejixie.com/article46/coephg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、品牌網(wǎng)站設(shè)計、自適應(yīng)網(wǎng)站、外貿(mào)建站、企業(yè)建站、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)