Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!pasteur!ucbvax!decwrl!purdue!i.cc.purdue.edu!j.cc.purdue.edu!pur-ee!uiucdcs!uiucdcsp!johnson
From: johnson@uiucdcsp.cs.uiuc.edu
Newsgroups: comp.lang.smalltalk
Subject: Re: Is SELF a naughty OOP construct?
Message-ID: <80500035@uiucdcsp>
Date: 31 May 88 17:26:00 GMT
References: <1620001@hplb29a.HPL.HP.COM>
Lines: 41
Nf-ID: #R:hplb29a.HPL.HP.COM:1620001:uiucdcsp:80500035:000:1540
Nf-From: uiucdcsp.cs.uiuc.edu!johnson    May 31 12:26:00 1988


Alan Lovejoy wishes that it were possible to write a single operation
that would work commutitively.  In other words, he wants to write one
method that will handle both Integer + Float and Float + Integer.
The solution is double dispatching and support from the programming
environment.  What you want is

Integer + anObject
	^anObject addInteger: self

Integer addInteger: anObject
	

Integer addFloat: anObject
	^anObject addInteger: self

Float + anObject
	^anObject addFloat: self

Float addInteger: anObject
	^self addFloat: (anObject asFloat)

Float addFloat: anObject
	...


Note that you have to write Float + Float, Integer + Integer, and
Float + Integer, but the system can automatically construct the
other three methods if it knows that + is commutitive.  Kurt Heeble 
and I are writing a paper about this.

The original question might have been concerned about the fact that
when you write "self" you don't know exactly what it means.  A subclass
can redefine all the messages to self, so the meaning of the code in
the superclass is hard to define.  If this is your concern, don't
worry about it.  This is a very important part of object-oriented
programming, and is necessary for abstract classes and frameworks.
In my opinion, no language without this feature can be called
object-oriented.  Of course, you could implement it without having
a distinguished receiver of the message named "self".  The Common
Lisp Object System does not have self, so self is an optional, if
useful, feature of an o-o language.