Re: Subclass of NSMutableDictionary hanging
Re: Subclass of NSMutableDictionary hanging
- Subject: Re: Subclass of NSMutableDictionary hanging
- From: Nick Forge <email@hidden>
- Date: Sun, 4 Mar 2007 22:00:02 +1100
On 04/03/2007, at 8:04 PM, Chris Hanson wrote:
On Mar 2, 2007, at 10:31 PM, Nick Forge wrote:
I am developing a preferencePane that makes use of a subclass of
NSMutableDictionary. My subclass (SPPowerSourceSettings) has only
three methods, which is one custom init method and a pair of "get
and set" methods.
Unlike other responses, I'll question why you're subclassing
NSMutableDictionary for this. I would subclass NSMutableDictionary
to provide a new "kind" of dictionary -- e.g., one that uses a
different internal representation -- rather than because I want to
use an NSMutableDictionary as backing store for an instance of an
object.
In the latter case, I'd just have an NSMutabelDictionary as an
instance variable, and have the appropriate accessor methods in my
class call through to it. The general rule of thumb is to use
subclassing for "is-a" relationships between classes and
composition for "has-a" relationships.
How do you define the difference between "has-a" and "is-a" when I'm
extending the features of what is basically an NSMutableDictionary? I
would've thought that that "is-a" NSMutableDictionary, since my class
(which is now a wrapper btw, which works great) has no other instance
(or static) data other then an NSMutableDictionary.
Are you saying that the only reason to subclass is to have different
(of modified) behaviour to pre-existing methods?
Is your "design philosophy" one based in many languages, or mostly in
Cocoa? I'm interested in hearing peoples opinions, since I have a lot
of programming experience, but very little real OOP experience.
The embedded programmer in me tries not to have unnecessary layers of
abstraction (e.g. having an instance of NSMutableDictionary inside a
wrapper class) due to speed and memory restrictions. Perhaps I have
to adjust my attitudes from working with 40Mhz and 1.5KB of RAM to
running on an xGhz Mac. I have also done a bit of other programming
where speed was a priority - so I'm in the mindset of eliminating
redundant wrappers and the like. I guess that's got to change in Cocoa.
If you were programming in say, Java, would it be "wrong" to subclass
an equivalent of NSMutableDictionary just to add some custom init and
instance variable accessor methods?
Thanks,
Nick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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