The interface has the following:
Animal* myPet;
At runtime, I may want myPet to be a cat or dog, which are subclasses of Animal:
id newPet; if(someCondition) { newPet = [[Cat alloc] initWithNibName:@"Cat" bundle:nil]; } else { newPet = [[Dog alloc] initWithNibName:@"Dog" bundle:nil]; } self.myPet = newPet;
Obviously, this is not true, but I hope it is enough to show what I'm trying to do. What is the best practice for this?
source share