다음을 통해 공유


Singleton Design Pattern

https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/singletondespatt.asp

 

singleton – a single object.

 

Important tidbits gleaned from the article:

 

  • The Singleton pattern lives in a family of creational patterns. Creational patterns dictate how and when objects get created.
  • The intention of the Singleton pattern is to provide a single point of object access in an object oriented application. This helps you guarantee that there is only one instance of this class throughout the application. Additionally, you escape the responsibility of having to monitor and control the number of running instances of the class.
  • Singleton classes should be sealed to avoid additional and unnecessary complexity when it comes to sub-classing.
  • When constructing singletons, you should designate the constructor as a private member of the class. This allows you to define when and how you construct a class instance and then keep any client from calling the constructor directly.
  • Public properties and methods can be defined to manipulate the instance data.
  • During the JIT process, the .NET Framework initializes static properties ONLY when they are first used.
  • The .NET Framework internally guarantees thread safety on static type initialization. If you define a static object, the framework guarantees that there is only one instance that will ever be created.