Double dispatching and Point

David N. Smith dnsmith at watson.ibm.com
Mon Feb 2 14:54:39 UTC 1998


At 22:45 -0500 1/31/98, Travis or Kerrin Griggs wrote:
>In doing this, I found that the by the time I was done with
>Point, it would have been much easier to make Point a subclass of Number.
>I could
>probably get rid of quite a few messages that way as well. Is there a good
>reason not to
>make Point a subclass of Number?


Yes, points are not magnitudes! The definition of #< in Point contains the
note:

   "Answer whether the receiver is above and to the left of aPoint."

while #> contains the comment:

   "Answer whether the receiver is below and to the right of aPoint."

Consider the following examples. In the first case, (2 at 2) is indeed less
than (3 at 3). In the next two however, (4 at 6) is neither greater than nor less
than (5 at 5).

(2 at 2) < (3 at 3)
 true

(5 at 5) < (4 at 6)
 false

(5 at 5) > (4 at 6)
 false

However, to be a magnitude #< and #> must be defined for all values such
that if the values are not equal either #< or #> will answer true. The
comment for class Magnitude says:

  I am an abstract representation of objects that measure something linear.

If one object can be neither less-than nor greater-than another then the
objects are not 'linear'.

Note that at least one major Smalltalk implementation (not IBM) gets this
wrong. I guess it's OK if inheritence is considered strictly for
implementation purposes, but that's how one ends up with Process being a
subclass of a collection (as in some Digitalk systems).

I'd vote for having some is-a view point mixed in with the
only-implementation viewpoint.

Dave

_______________________________
David N. Smith
IBM T J Watson Research Center
Hawthorne, NY
_______________________________
Any opinions or recommendations
herein are those of the author
and not of his employer.





More information about the Squeak-dev mailing list