Singleton Design pattern has :
- It has private constructor so that instance of class cannot be created anywhere but inside its own methods.
- It has static read only member so that instance is created only once .
- It has an instance property to return singleton object instance
public sealed class Singleton
{
// private constructor
private Singleton()
{
}
// static readonly member
static readonly Singleton instance = new Sinleton();
// static instance property
public static Singleton Instance
{
get { return instance ; }
}
}
No comments:
Post a Comment