using System;
namespace test
{
public class Factory<T>
where T : Factory<T>, new()
{
public virtual T Make()
{
return new T();
}
}
public class DerivedA : Factory<DerivedA>
{
public DerivedA() { Console.WriteLine("DerivedA ctor"); }
}
public class DerivedB : Factory<DerivedB>
{
public DerivedB() { Console.WriteLine("DerivedB ctor"); }
}
static class main
{
static void Main(string[] args)
{
DerivedA a = new DerivedA();
DerivedB b = new DerivedB();
DerivedB binst = b.Make();
DerivedA ainst = a.Make();
}
}
}