Skip navigation.
 
mlRe: NSData (again!)
FROM : Sheehan Olver
DATE : Sat Dec 14 19:55:55 2002

   It really depends on the class in question. One issue is that many
classes really hide a complex tree of subclasses. The most obvious
example is NSNumber, which has specific subclasses for floats, ints,
etc. So when you do [NSNumber numberWith], you are really getting an
instance of a subclass. In fact, if you were to subclass NSNumber you
would have to practically reimplement the entire class. By wrapping
NSNumber, you let it do what it needs to do. This applies to other
classes as well, such as NSArray, NSString, NSMutableString, etc, and
I'm pretty sure NSData is like that as well, with  hidden subclasses to
make the storing as efficient as possible. A general rule of thumb is
to only subclass classes that you have to, like NSView. Since it's
possible to actually pose as an other class (so your wrapper
effectively would be, as far as other objects are concerned, an
instance of NSData), You can avoid all the problems with subclassing
and get most of the benefits you were looking for.

On Saturday, December 14, 2002, at 08:40  AM,
<email_removed> wrote:

> Date: Sat, 14 Dec 2002 23:32:58 +0900
> Subject: NSData (again!)
> From: Pascal Goguey <<email_removed>>
> To: <email_removed>
>
> Hello!
>
> Summary of the history:
> The other day, I asked a question about how to subclass NSData
> from the interface builder. I got a few replies (thanks again), and
> learned
> about forwardInvocation which is a very nice concept. All the replies
> I got were telling me that "I should not subclass NSData" or "I
> probably
> don't want to subclass NSData".
>
> I guess it is probably true, that there is probably a good technical
> reason
> to prefer wrapping to inheritance, otherwise the people who wrote
> Project Builder and Interface Builder would have enabled the
> possibility
> to subclass NSData.
>
> Now, what I need to know is WHY it is bad practice to subclass.
> There are some subclass (e.g. NSApplocation inherits from NSResponder).
> So why should my class not inherit NSData, but only wrap it?
>
> Thanks,
>
> Pascal

_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlNSData (again!) Pascal Goguey Dec 14, 15:32
mlRe: NSData (again!) Joe Osborn Dec 14, 17:38
mlRe: NSData (again!) Sheehan Olver Dec 14, 19:55