I'm trying to create some code that detects all concrete implementations of an interface within c#. However I dont believe the problem I am facing is confined to c# and is a general oop question.
I want to do the detection at runtime so I have the ability to expand the implementations of the interface at a future date.
What options/approaches are available to me in order to achieve this?
for example
public interface IAnimal{
void MakeNoise();
}
public class Dog : IAnimal{
public void MakeNoise()
{
Console.WriteLine("WOOF");
}
}
public class Cat : IAnimal{
public void MakeNoise()
{
Console.WriteLine("Meow");
}
}
public class AnimalInstanceController{
/*Im trying to populate this with all classes that implement IAnimal
*/
public IEnumerable<IAnimal> {get;set;}
}
Thanks
Nicholas