Re: Need to override +(Class) class?
Re: Need to override +(Class) class?
- Subject: Re: Need to override +(Class) class?
- From: Stuart Rogers <email@hidden>
- Date: Sun, 28 Sep 2008 10:53:51 +0100
On 28 Sep 2008, at 10:02, Dave DeLong wrote:
I'm building an app, and I've got a bunch of interface object
definitions called "InputElements". There are a couple subclasses,
such as InputElementButton and InputElementSlider.
I'm building the interface via an "InputMode" object, that contains an
array of InputElement objects. As I build the interface, I loop
through the InputElement objects in the InputModes array, and am doing
the following:
for (InputElement * element in [inputMode elements]) {
if ([element isKindOfClass:[InputElementButton class]]) {
//build an InputViewButton
} else if ([element isKindOfClass:[InputElementSlider class]]) {
//build an InputViewSlider
}
}
As an aside... If InputElementButton and InputElementSlider had a
common superclass, and InputViewButton and InputViewSlider had a
common superclass, you could simplify your code along the lines of:
for (InputElement * element in [inputMode elements])
{
InputView *inputView = [element buildInputView];
// ...
}
...where -buildInputView is declared by the InputElement superclass
and overridden by the subclasses as necessary, returning a suitable
InputView subclass.
Of course you might have good reason to know the class at run time,
but in most cases I've come across (in my limited experience) there's
usually a simpler approach that avoids it.
Stuart
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden