• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSData (again!)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSData (again!)


  • Subject: Re: NSData (again!)
  • From: Sheehan Olver <email@hidden>
  • Date: Sat, 14 Dec 2002 12:55:55 -0600

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@hidden wrote:

Date: Sat, 14 Dec 2002 23:32:58 +0900
Subject: NSData (again!)
From: Pascal Goguey <email@hidden>
To: email@hidden

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@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.

  • Prev by Date: NSTabView delegate question
  • Next by Date: Re: How to run prefPane from Project Builder/gdb
  • Previous by thread: NSTabView delegate question
  • Next by thread: NSProgressIndicator into a NSTableView cell?
  • Index(es):
    • Date
    • Thread