Re: Mutability
Re: Mutability
- Subject: Re: Mutability
- From: Drew McCormack <email@hidden>
- Date: Wed, 21 Nov 2001 18:21:23 -0800
Those "Class*" things in newer ObjC are just hints for compiler to be
able
to solve some situations with non-OO data properly, and perhaps to warn
us
when we made a mistake; it should *NOT* mess up with the runtime object
system though, or we are bound to go the C++ way to hell!
I don't think any of us want that ;-)
DMC> Really, using things like "isKindOfClass" is often a symptom of bad
DMC> design.
Is it?!? I'd say it is a symptom of _THE PROPER_, ie. run-time design,
as
compared with the bad, C++-like compile-time one!
Well, I don't know if I can agree with this. The problem with
"isKindOfClass:" is that people end up going right past C++ to C. What I
mean is, they put in if/then/else branches where OO branching (ie
polymorphism) could be used.
You get
if ( [soAndSo isKindOfClass:@class(Class1) ) {
// do something
} else if ( [soAndSo isKindOfClass:@class(Class2) )
// do something else
} else
...
The problem with this is when you later add another class to the
program, you need to find all of these branches and add another branch
to them. Obviously sometimes this sort of thing is necessary, but often
it isn't, and it is one of the reasons OO was invented in the first
place.
If I find myself using a runtime identification method in my program, I
always think twice, to make sure I am not limiting the flexibility of my
program through bad design.
Drew McCormack