Re: Multiple NSTableView question
Re: Multiple NSTableView question
- Subject: Re: Multiple NSTableView question
- From: "David P. Henderson" <email@hidden>
- Date: Thu, 21 Jun 2001 10:58:04 -0400
On Thursday, June 21, 2001, at 09:24 , Phillip Mills wrote:
>
Being new to Obj-C and Cocoa....
>
>
This seems very non-OOP and I wonder whether it's a normal Obj-C
>
idiom. (?)
>
I would have expected something like:
>
>
- (int)numberOfRowsInTableView:(NSTableView *)theTableView
>
{
>
[theTableView doSpecialStuff];
>
[self doCommonStuff];
>
}
>
>
But this, of course, requires extensions to NSTableView...sub-class,
>
category...? Using PowerPlant, I would have automatically considered
>
sub-classing (because it's really easy) if doSpecialStuff was at all
>
complex. Is polymorphism for UI classes abnormal here?
>
Why? At some point you still have to make the determination of with
which table view you are working. And using a subclass to do so is
complete overkill, better to use conditional testing to make the
determination. If you don't like doing raw pointer comparison then use:
if ([theTableView isEqual:myFirstTable])
...
Subclassing in ObjC is even easier but generally not required as in C++.
And the majority of subclasses in Cocoa apps are subclasses of NSObject.
Also if you do need specialized behavior in a Cocoa (obj-c) class but
don't need to add any data members (ivars), categories are a better way
to go than subclassing.
Dave
--
Chaos Assembly Werks
"Imagination is more important than knowledge."
- Albert Einstein