isKindOf: vs. isClassX methods

Norton, Chris chrisn at Kronos.com
Wed Oct 10 23:14:13 UTC 2001


...snipped good points from others...

Another thing to consider, Eddie, is that #isKindOf: on most Smalltalks
refers not only to the class you are checking, but also to it subclasses.
This may or may not be what you're after.

For example, if I create a class Human, with two subclasses, Chris and
Eddie, then asking some object #isKindOf: Human may make sense for Eddie,
but perhaps not for Chris (this distinction is probably debatable).

In any case, I wanted to chime in and agree that general use of #isKindOf:
should be limited.  Not only is it a more time consuming operation (its got
to check all those subclasses, after all), but it also implies that you are
not really too sure what kind of object you're dealing with and that is
rarely a good thing.  

You should strive to provide polymorphic methods for the classes you expect.
Classes that do not support to the interface you've defined for your
component are undoubtedly unfinished.

Cheers,

---==> Chris





More information about the Squeak-dev mailing list