Sigh. In Defense Of Inheritance

Bill Frantz frantz@netcom.com
Sun, 25 Oct 1998 00:36:04 -0800


One possible "ease of delegation" mechanism is to have a "default" method.
Speaking at the level of abstraction of the E vat method dispatcher, if an
object is invoked with a method selector string which is not defined in the
object, and the conventionally named default method is defined, then it is
invoked:

  E.send(object, "default", invokedMethodName, parameters)

The default method could be coded:

  public void default(String invokedMethodName, Object[] parameters) {
     E.send(delegatee, invokedMethodName, parameters);
  }

Interface narrowing would look like:

  public void default(String invokedMethodName, Object[] parameters) {
     if (invokedMethodName.equals("foo")
           || invokedMethodName.equals("bar")) {
        E.send(delegatee1, invokedMethodName, parameters);
     } else {
        throw new InvalidMethodNameException(invokedMethodName);
     }
  }

Multiple inheritance would look like:

  public void default(String invokedMethodName, Object[] parameters) {
     if (invokedMethodName.equals("foo")
           || invokedMethodName.equals("bar")) {
        E.send(delegatee1, invokedMethodName, parameters);
     } else {
        E.send(delegatee2, invokedMethodName, parameters);
     }
  }

This construct avoids the real sin of multiple inheritance, which is behind
the programmer's back confusing semantics.


-------------------------------------------------------------------------
Bill Frantz       | Macintosh: Didn't do every-| Periwinkle -- Consulting
(408)356-8506     | thing right, but did know  | 16345 Englewood Ave.
frantz@netcom.com | the century would end.     | Los Gatos, CA 95032, USA