Re: Determining if NS/CFDictionary is mutable?
Re: Determining if NS/CFDictionary is mutable?
- Subject: Re: Determining if NS/CFDictionary is mutable?
- From: "Philippe Mougin" <email@hidden>
- Date: Tue, 24 Dec 2002 17:38:11 +0100
>
From an API point of view, there is no way to tell if something is
>
mutable or not
Why this weird design? There are cases where it would be legitimate and
useful to "know" if a given dictionary is mutable or not. I tend to think
that a top-notch, dynamic object-oriented API like Cocoa should at least
support this kind of functionality!
For instance, suppose I want to develop a function that does the following:
-Takes a custom object as argument (i.e. declared as "id")
- If the argument is not, at run-time, a dictionary, opens a generic
graphical object inspector that displays a short description of the object
(lets say, using the polymorphic "description" method).
- If the argument is, at run-time, a non-mutable dictionary, opens a
graphical inspector that lets the user conveniently look at the contents of
the dictionary.
- If the argument is, at run-time, a mutable dictionary, opens a graphical
inspector that lets the user conveniently look at the contents of the
dictionary and modify the dictionary itself (add/remove entries etc.)
AFAIK, I can't do it, because of the current Cocoa design. Don't you think
it may be worth re-evaluating it on this point?
Seems to me that there is a more general problem in the current design. It's
the fact that the non-mutable dictionaries are instances of a class which
inherits from NSMutableDictionary. We end-up with a subclass
(NSCFDictionary) which breaks (in a big way) the documented contract of one
of its superclass (NSMutableDictionary). This is super counter-intuitive,
error prone, and in contradiction with established "good practices" in the
OO field (for insance, we all know that breaking the substitution principle
is not a good practice unless we have a very, very compelling reason to do
so. Maybe there is one in this case. If so, please, enlighten us). It would
be nice to see things fixed. I'm sure that I am not the only one who think
that a technology like Cocoa should not be cluttered by things like this,
but should, on the contrary, strives for the highest degree of quality in
its design.
Introducing the mutability/immutability concept in Core Foundation may be
the way to go, or maybe should this concept be dropped from Cocoa,
preserving only the mutable versions of the collection classes...
Best,
Phil
_______________________________________________
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.