I have a certain class, namely Animal
, and several subclasses like Dog
, Cow
, Lion
, etc.
Animal
is an abstract class which has an abstract static method eats(Food f)
.
All of these subclasses implement eats
and, according to each animal, will either return True
or False
.
How can I iterate through each of those and create a new Animal
whose type eats
that specific food without manually typing each class?
For example, I'd like to get an object of type Animal
that eats grass, without actually creating a new Cow
.
Finding the subclasses of Animal
may be one part, but I am more interested in actually iterating some sort of list of classes and running eats
on each of them, until I find one that returns True and then create a new object of that class.
Thanks.