florman@randvax.UUCP (Bruce Florman) (04/05/89)
The other day I got to wondering how Eiffel would resolve a reference
to a feature for which, through repeated inheritance and redefinition, the
object's dynamic type had more than one definition. OOSC didn't seem to
say how it would be done (of course I may have overlooked something), so I
wrote the following small program as a test.
CLASS A EXPORT do_it
INHERIT STD_FILES
FEATURE
do_it IS DO output.putstring_nl("Doing it from A") END
END -- CLASS A
CLASS B
INHERIT A REDEFINE do_it
FEATURE
do_it IS DO output.putstring_nl("Doing it from B") END
END -- CLASS B
CLASS C
INHERIT A REDEFINE do_it
FEATURE
do_it IS DO output.putstring_nl("Doing it from C") END
END -- CLASS C
CLASS D
INHERIT B RENAME do_it AS do_it_from_b;
C
END -- CLASS D
CLASS E
INHERIT C;
B RENAME do_it AS do_it_from_b
END -- CLASS E
CLASS F
FEATURE
Create IS
LOCAL an_a: A; a_d: D; an_e: E
DO
a_d.Create;
an_a := a_d;
an_a.do_it;
an_e.Create;
an_a := an_e;
an_a.do_it
END
END -- CLASS F
Executing the resulting binary produces the following result.
%f
Doing it from C
Doing it from B
%
Obviously the order in which a class inherits its ancestors has an effect
on the semantics of such a reference. I wonder, however, if the result we
see here (ie. last inheritance takes precedence) can be relied upon, or if
the result should be considered implementation dependent. Any comments?
-BRUCE Florman (florman@rand.org)
-The RAND Corporation
Since RAND has decided that its name is spelled
with all caps, I've decided that mine is too.