Say for example I have some classes which all inherent from the same parent class and have the same parameters. A common example;
class Pet():
...
class Cat(Pet):
__init__(self,name,colour):
Pet.__init__(self,name,colour)
....
class Cactus(Pet):
__init__(self,name,colour):
Pet.__init__(self,name,colour)
....
And then say I want to instantite some type of pet later in the program based on user input. What I would think of doing at first is;
if(pet_type == 'Cat'):
animal = Cat(name,colour)
elif(pet_type == 'Cactus'):
animal = Cactus(name,colour)
etc...
But is there a better way that does not require an if? For example if the program was developed to include over 1000 animals which all descend from pet then it would not be feasilbe.