• 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: Know about Mutability
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Know about Mutability


  • Subject: Re: Know about Mutability
  • From: Angela Brett <email@hidden>
  • Date: Sat, 15 Jan 2005 01:59:55 +1300

Is there a good reason that NSDictionary inherits from NSMutableDictionary, rather than the other way round?

Maybe I'm just not thinking straight because it's 1:59a.m and I've been up all night coding, or maybe I'm thinking particularly clearly for the same reason, but here's my take on it. Bear in mind that I haven't read this entire thread (just several previous threads on the same topic) and I don't know the actual organisation of NSDictionary, NSMutableDictionary and their concrete subclasses.


Implementing NSMutableDictionary as a subclass of NSDictionary would require either:

a) Intimate knowledge of how NSDictionary's private instance variables are used. The people who wrote NSMutableDictionary probably have this, since they most likely wrote NSDictionary and have all the source code, but nonetheless it's generally a bad idea for a subclass to be relying on all the internal details of how its superclass is implemented.

or:

b) Reimplementing just about everything in the subclass because you can't use NSDictionary's public methods to do any of the required mutating. You'd end up having to handle your own mutable data storage, and probably rewrite even the methods that are already in NSDictionary, to use that storage. That would pretty much defeat the purpose of it being a subclass, it may as well just be its own class.

On the other hand, making an NSDictionary subclass of NSMutableDictionary would be a simple matter of overriding a couple of methods to throw exceptions (although I guess they do other things to improve efficiency since there are so many things you don't have to worry about with immutable objects.) So even though it seems weird conceptually because you're taking away functionality in a subclass rather than adding it, it actually makes a lot of sense in terms of actual implementation.
--
Angela Brett
email@hidden
http://NSCoder.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >Re: Know about Mutability (From: James Bucanek <email@hidden>)
 >Re: Know about Mutability (From: mmalcolm crawford <email@hidden>)
 >Re: Know about Mutability (From: Andrew Pinski <email@hidden>)
 >Re: Know about Mutability (From: mmalcolm crawford <email@hidden>)
 >Re: Know about Mutability (From: Hugh Hoover <email@hidden>)
 >Re: Know about Mutability (From: Peter Maurer <email@hidden>)
 >Re: Know about Mutability (From: Paul Sargent <email@hidden>)

  • Prev by Date: Re: Bindings Book !!!!!
  • Next by Date: Re: Reveal in Finder Sample Code
  • Previous by thread: Re: Know about Mutability
  • Next by thread: Re: Know about Mutability
  • Index(es):
    • Date
    • Thread