Re: WTF? How can this work?
Re: WTF? How can this work?
- Subject: Re: WTF? How can this work?
- From: Ondra Cada <email@hidden>
- Date: Sun, 19 Aug 2001 22:55:43 +0200
Chris,
as for the more generic points, I would just duplicate the Erik M. Buck's
message: my very own words. Otherwise:
>
>>>>> Chris Kane (CK) wrote at Sun, 19 Aug 2001 11:11:40 -0700:
CK> >(im)mutability brought information as well, ie. I had code like
CK> >
CK> >id o=...;
CK> >...
CK> >if ([o isKindOfClass:[NSMutableArray class]]) { ... code A ... }
CK> >else if ([o isKindOfClass:[NSArray class]]) { ... code B ... }
CK> >...
CK>
CK> This is just a bad idea. You should rarely be basing a decision on
CK> whether or not the dynamic runtime type of an object is mutable or not.
CK> You should be coding to the API's contract, as specified by the return
CK> type.
Uh-oh, seems I've written too little of using this thing. Of course, I
couldn't do this for some generic return values. *BUT*, this seems to me
quite all right for a property list (made and maintained by me), which
contains different objects.
For example (it is similar to my real app, though not exactly same), suppose
I am to store some UI definitions to an array, and for some reason or
another I can't use real UI objects, *AND* want to keep the array contents as
simple as possible. BEsides, the UI is limited to buttons, pop-ups, and
combos (which would change the lists of their popup strings dynamically).
Well, so I create an array which contains NSStrings for buttons, NSArrays
for popups, and NSMutableArrays for combos. The code then would look like
if ([o isKindOfClass:[NSString class]]) { ... add a button with title o ... }
else if ([o isKindOfClass:[NSMutableArray class]]) { ... add a combo with
list o ... }
else if ([o isKindOfClass:[NSArray class]]) { ... add a popup with items
from o ... }
Of course I can do it other way (like specifying first array item to contain
"combo" or "popup", or placing the desired class name into the structure, or
whatever). It would unnecessarily complicate the plist, though.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc