isKindOf: vs. isClassX methods

Ned Konz ned at bike-nomad.com
Wed Oct 10 21:05:00 UTC 2001


On Wednesday 10 October 2001 01:41 pm, Eddie Cottongim wrote:
> I've noticed in many places in the image there are methods such as isColor
> or isMorph that identify the 'type' of an object. (See: Object category
> testing, Morph category classification). I always thought that this kind of
> test was done with "isKindOf:".

If what you're testing is whether an object provides a certain interface, use 
respondsTo: or make an isXXX method, or use exception handling and catch the 
MessageNotUnderstood signal.

If what you're testing is actually whether something is at a particular place 
in the inheritance hierarchy, use isKindOf:

But often we don't care where an object is in the inheritance hierarchy, we 
just want to test its interface, which makes isKindOf: a potential trouble 
spot (after all, who knows whether someone might add that interface to 
another kind of object entirely?).

Many of the current uses (750+ of them!) of isKindOf: are Morphs testing 
their submorphs to apply various operations to them.

-- 
Ned Konz
currently: Stanwood, WA
email:     ned at bike-nomad.com
homepage:  http://bike-nomad.com




More information about the Squeak-dev mailing list