I have a question on the best way to setup a list of objects.
Say I have a base class called Animals. For example say I have a list that contains 4 Animals (could be lots more than but this is just a simple example).
I also have four other objects that all inherit from the Animals class. Lets call them Dog, Lion, Monkey & Cat.
At run time I have no idea which of the four objects will need to be intialised, it could be 4 dogs or 2 monkeys, 1 cat & 1 lion etc.
Currently I am using a if statement block which works but was wondering if there was a better way of doing this.
for(int i =0 ; i < AnimalsSelected.Lenght; i++)
if(AnimalsSelected[i].Name == "Dog")
Animals[i] = new Dog();
elseif (AnimalsSelected[i].Name == "Lion")
Animals[i] = new Lion();