Classes as Packages (was: Harvesting infrastructure)

Anthony Hannan ajh18 at cornell.edu
Mon Nov 18 20:50:12 UTC 2002


Hi Tim, I agree with your points, especially that composition/delegation
is more appropriate in many cases, like the toy truck.  But multiple
inheritance is still useful, look at the Morph classes for instance, and
its is useful for class extensions.  Your point on method lookup is
important and I haven't wrote about that yet, so here it is:

The order of paths searched doesn't matter.  If a selector is overriden
in two separate paths then it is ambiguous and an error will result on
method lookup.  In other words, all topological sorts of the superclass
hierarchy of a given class should yield the same first method for a
given selector.  If not, then the class is ambiguous on that selector.

I am assuming a good enough method cache so the lookup algorithm
presented below won't be executed enough to significantly effect
performance.  Here's the recursive algorithm:

	1. If the selector is implemented locally then return that method,
otherwise
	2. Recursively find the selector's method for each superclass.
	3. Remove 'notFound' results from the result set.
	   If the result set is empty return 'notFound',
	   if all objects in the result set are the same method then return it,
	   otherwise return 'ambiguous'

If the final result is 'ambiguous' or 'notFound' then an error is
raised.  If we use memoization the time complexity is O(v+e), where v is
the number of all superclasses of the receiver class and e is the number
of edges between them.

With respect to super calls.  I would keep the general 'super' which
would just skip step 1 the first time for the method's class.  We can
add specific super reference using syntax such as 'super.Truck message'
or something like that, or we can not have it at all but I think it
would save people from copying code.

Cheers,
Anthony



More information about the Squeak-dev mailing list