fyi: the DoFactory design-pattern collection (commercial software) has some good tutorials (free): check out their tut on the Factory Pattern: [
^]. note: i purchased their software a few years ago, and have learned a lot with/from its rigorously formal consistent content ... and, style.
What you are doing seems overly complicated: see if this code gives you any ideas.
usage:
Dog dog = AnimalFactory.NewAnimal<Dog>("Mangy");
Cat cat = AnimalFactory.NewAnimal<Cat>("Mouser");
code for AnimalFactory:
using System;
namespace YourFactory
{
public interface IAnimal<T>
{
string Name { get; set; }
}
public class Dog: IAnimal<Dog>
{
public Dog(string name)
{
Name = name;
}
public string Name { get; set; }
}
public class Cat: IAnimal<Cat>
{
public Cat(string name)
{
Name = name;
}
public string Name { get; set; }
}
public static class AnimalFactory
{
public static T NewAnimal<T>(string name) where T : IAnimal<T>
{
return (T) Activator.CreateInstance(typeof(T), name);
}
}
}