Description: The Singleton Pattern ensures a class has only one instance and provides a global point of access to it.
Pros:
Cons:
Practical Usage:
Sample Implementation:
public sealed class Singleton
{
private static Singleton instance = null;
private static readonly object padlock = new object();
Singleton() { }
public static Singleton Instance
{
get
{
lock (padlock)
{
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
}
}
Description: The Factory Pattern defines an interface for creating an object, but allows subclasses to alter the type of objects that will be created.
Pros: