• français (France)
    • English (United States)
    • العربية (مصر)
    • Deutsch (Deutschland)
    • Español (España, alfabetización internacional)
    • हिंदी (भारत)
    • italiano (Italia)
    • 日本語 (日本)
    • 한국어 (대한민국)
    • Nederlands (Nederland)
    • polski (Polska)
    • русский (Россия)
    • ไทย (ไทย)
    • Türkçe (Türkiye)
    • Tiếng Việt (Việt Nam)
    • 中文(中华人民共和国)
    • 中文(香港特別行政區)
  • Connexion
  • Registre
DotNetAge - Mvc & jQuery CMS
Masquer la barre latérale

Singleton


Definition



Ensure a class has only one instance and provide a global point of access to it.

With the Singleton Design Pattern in place, the developer can easily access that single object instance without needing to worry about inadvertently creating multiple instances, and provides a global point of access to it.

UML class diagram





Participants



The classes and/or objects participating in this pattern are:
Singleton
  • defines an Instance operation that lets clients access its unique instance. Instance is a class operation.
  • responsible for creating and maintaining its own unique instance.

Sample code in C#




public class SingletonSample
{

//shared members
private static SingletonSample _instance = new SingletonSample();

public static SingletonSample Instance()
{
return _instance;
}


//instance members
private SingletonSample()
{
//public instantiation disallowed
}

//other instance members
//...
}

 


    Average:
  • Lectures
    (732)
  • Permalien
Partager à:

Tag cloud

Anything in here will be replaced on browsers that support the canvas element