[E-Lang] Re: inheritance, delegation, mental models for beginners (was: down with `define' (was: newbie syntax: picayune points from a prejudiced programmer))

zooko@zooko.com zooko@zooko.com
Fri, 02 Mar 2001 12:06:21 -0800


 MarcS wrote:
> 
> Unfortunately, there is an important difference: if the subclass overrides a
> method in the superclass, when the superclass calls that method it goes back
> out to the subclass's method. With delegation, a delegated-to class call to
> the overridden method is directed to the delegated-to class implementation.
> So I like your theory, I yearn to accept it, but I can't buy it :-)


To me this is still inheritance.  The salient difference between
inheritance and delegation to me is:


In inheritance, the "parent object" is (normally) one-to-one with the
child object.  I.e. if there is an existing object with its own state
and I "inherit" from it, then I want a copy of the state (optionally a
clean slate), rather than a link to shared state.  


There are many other very interesting issues about this, including
subtyping relations, class-based vs. object-based and dynamic vs.
static, and the behaviour of recursive method invocations (which are,
in fact, a facet of the perennial conundrum of covariance), but none of
these, and least of all the last one, should preclude the name
"inheritance".



Heck, in C++ "inheritance" the default behaviour (without the "virtual"
keyword) was neither the superclass nor the subclass, but the class
which corresponded to the static type of the pointer!  :-)


And C++ is by far the most widely used O-O language according to
sourceforge.


I still think it is fair to say that E has inheritance, and then to
explain to those 2% of the population who care, that is more like
Smalltalk's "delegation" than Java's "inheritance", and it is a little
like C++'s "inheritance (without the virtual keyword)", but better.


  :-)



But I'm curious about this:  is this behaviour (superclass methods
invoking other superclass methods instead of the subclass's override)
considered to be an advantage semantically or just easier to implement?


I think I would prefer that the superclass invoke the subclass's
method.


When I said that I preferred delegation over inheritance I simply meant
that I didn't want code re-use to imply subtyping.  I also meant that 
I wanted to be free to re-use code from objects without necessarily
having to deal with that object's class (which is a fine distinction
that might actually be an empty distinction in E).


Hm.


Regards,

Zooko