Calling the same function in multiple classes
Calling the same function in multiple classes
- Subject: Calling the same function in multiple classes
- From: Andrew Merenbach <email@hidden>
- Date: Mon, 4 Nov 2002 21:28:52 -0800
In a program I'm making, a matrix of buttons in a window (each with a
different tag) causes the contents of the window to change (to a new
"feature"), and when the user returns to the main screen the content
view is changed back. I currently have code that looks like this:
- (IBAction)changeMainView:(id)sender
{
switch([[sender selectedCell] tag]) {
case 0: [[CBMolarityController sharedInstance] showView];
break;
case 1: [[CBDilutionController sharedInstance] showView];
break;
case 2: [[CBSolubilityController sharedInstance] showView];
break;
case 3: [[CBConcentrationController sharedInstance] showView];
break;
case 4: [[CBNormalityController sharedInstance] showView];
break;
case 5: [[CBTitrationController sharedInstance] showView];
break;
case 6: [[CBMolalityController sharedInstance] showView];
break;
}
}
I had the bright idea that it might run more quickly if I were to do
the following:
- (IBAction)changeMainView:(id)sender
{
static NSArray *solutionsArray;
if (!solutionsArray) solutionsArray = [[NSArray alloc]
initWithObjects:[CBMolarityController
sharedInstance],[CBDilutionController
sharedInstance],[CBSolubilityController
sharedInstance],[CBConcentrationController
sharedInstance],[CBNormalityController
sharedInstance],[CBTitrationController
sharedInstance],[CBMolalityController sharedInstance]];
[[solutionsArray objectAtIndex:[[sender selectedCell] tag]]
showView];
}
It looks convoluted, but runs well. Is there any particular
reason--other than the obvious "it's convoluted!"--not to use it? Most
notably, will I most definitely *not* have a speed improvement with the
second method? Or is it even poor coding?
Take care,
Andrew Merenbach
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.