s872625@minyos.xx.rmit.oz (Chris Cogdon [Brataccas]) (04/10/90)
I have found a possible bug/design fault/undocumented feature with the
Eiffel design/implementation and was wondering if someone could enlighten
me to its purpose. Apols. if this item has already been discussed.
The problem lies with repeated inheritance. An example:
class A
export i
feature i : INTEGER
end -- class A
class B
inherit A rename i as i1;
A rename i as i2;
end -- class B
Assume proper Create clauses and something to set the values of the
attributes. Pardon the indenting too.
In some routine:
local obj_a : A;
obj_b : B
do
b.Create;
-- set values of b.i1 and b.i2 as, for example, 13 and 27 respectively.
a := b;
io.output.putint(a.i);
-- etc
In the implementation of Eiffel we have here, a.i will return 13 (the first
of the two). But the real value of a.i is debatable.
B conforms to A, certainly. But, in effect, there are two A's in B!! There
is no problem if repeated inheritance results in the one feature, but there
is a problem if it is duplicated when referenced from the original class
(as above).
I can see 3 solutions:
1. Make repeated inheritance of an exported (at or above the point
of duplication, class A above) feature that would result in
duplication an error (or at least a warning).
2. Formally define the above effect. ie. Referencing a feature which
is really, at run-time, a duplicated feature will access the first
listed in the inheritance clause. I'll call this the dominant feature.
This creates a problem if you want, for example, feature 'i' from the
first of a pair of inherited class 'A's, and 'j' from the second.
3. To solve the problem in 2. add a language construct to specifiy which
features in duplicated inheritance are 'dominant'.
This would not be a rarely occurring problem. Consider the US/French
Driver example from 'OO Software construction'. Create an instance of
US_FRENCH_DRIVER and assign to a DRIVER entity. If the classes have an
age(not duplicated) and licence number(duplicated). What would be
the result of driver_instance.licence_number??
Could someone elaborate what philosophy has been taken on this, and whether
or not it already is in the manuals, and I've overlooked it!!
-------------------------------------------------------------------------------
Chris Cogdon [Brataccas] s872625@minyos.xx.rmit.oz
All spelling and gramatical errors are the fault of a malicious filter.
Semantic errors are the fault of a warped mind.