Optimal way to initialize varying objects
- by John Smith
I have to initialize a lot of different types of objects based on an integer parameter. They all have the same overall initialization methods.
At the moment I have the following code
#def APPLE 1
#def PEAR 2
switch (t)
{
case APPLE:
newobj = [[FApple alloc] init];
break;
case PEAR:
newobj = [[FPear] alloc] init];
break;
default:
retobj = nil;
}
I believe there must be a better way to do this. When I add FOrange I have to go and add another line here.
What would be a better way?