Singletons and inheritance
Jon Skeet posted an example of Singletons and inheritance.
What do you think about this generic singleton solution? This way you dont have to update the factory method with each subclass creation. It would be neater if the new generics' constraint would support parameters, but you can overcome it with abstract method CreateInstance which returns T.
abstract class DataProvider<T> where T: new()
{
private static T mInstance = new T();
public T Instance
{
get
{
return mInstance;
}
}
public abstract void Connect();
}
class Oracle : DataProvider<Oracle>
{
public override void Connect()
{
Console.WriteLine ("Connecting to Oracle");
}
}
class SqlServer : DataProvider<Oracle>
{
public override void Connect()
{
Console.WriteLine ("Connecting to Sql Server");
}
}