In this design pattern, the number of objects for a class is restricted to one. Good example of it is thread pools and registry pools.
Following C# code implements this design pattern
public class Singleton
{
Following C# code implements this design pattern
public class Singleton
{
private Singleton()
{
// Any initialization
}
private static Singleton singleton;
public static Singleton Singleton
{
get
{
if (singleton == null)
{
singleton = new Singleton();
}
return singleton;
}
}
// Any further implementations...
} // End of singleton class
No comments:
Post a Comment