🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.eiffel
Article #1294

Re: Multiple inheritance and dynamic binding.

#1294
From: Jim Patterson
Date: Mon, 16 Jan 1989 15:01
62 lines
2658 bytes
In article <203@my2.luth.se> Mikael Degermark <micke@my.sm.luth.se> writes:
>Assume there is a class A that declares and exports a feature f:INTEGER.
>Assume there is two other classes B and C which each inherit A.
>Assume a fourth class D that inherits both B and C and renames f:
>
>    class D export f_b, f_c
>        inherit B rename f as f_b;
>        inherit C rename f as f_c;
>    ...
>
>Now, an instance of D has two distinct integer features f_b, f_c.
>
>Consider the following fragment of eiffel: (I hope it is eiffel ;->)
>
>    a:A;
>    b:B;
>    c:C;
>    d:D;
>
>    if a.f = ...   -- here is the problem!
>
>PROBLEM: Which of the features d.f_b and d.f_c is denoted by a.f?

a.f will in fact refer to d.f_c. There doesn't seem to be a
"theoretical" reason for this; it's more a consequence of the
implementation. f_c will be chosen because C's features are
initialized in class D after those of B and so override them.

An alternative implementation is possible whereby f_b and f_c would
refer to the same attribute. In your example, and from a's
perspective, this seems to make more sense. However, in other
examples, it may not.  Consider a class COORDINATE and a class AREA
implemented as follows.

class COORDINATE
FEATURE
   X,Y : INTEGER;
END;

class AREA
INHERIT
   COORDINATE rename x as x1, y as y1;
   COORDINATE rename x as x2, y as y2
END;

Here, AREA can refer independently to each of two (x,y) pairs.  If the
compiler made x1 and x2 refer to the same attribute, this would not be
possible.

On the other hand, the existing implementation means that COORDINATE
will only ever refer to x2 and y2 from an AREA object. This makes it
impossible for AREA to share COORDINATE code to deal with x1 and y1.
Clearly, there are some weaknesses in the implementation when it comes
to multiple inheritence of attributes. No doubt some of this is
inherent in the structure (it really is ambiguous whether you mean f_b
or f_c).

-- 
Jim Patterson                              Cognos Incorporated
UUCP:decvax!utzoo!dciem!nrcaer!cognos!jimp P.O. BOX 9707    
PHONE:(613)738-1440                        3755 Riverside Drive
                                           Ottawa, Ont  K1G 3Z4
Technical Details
Message-ID: <5031@aldebaran.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!dciem!nrcaer!sce!cognos!jimp
References: <203@my2.luth.se>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!dciem!nrcaer!sce!cognos!jimp
From: jimp@cognos.uucp (Jim Patterson)
Newsgroups: comp.lang.eiffel
Subject: Re: Multiple inheritance and dynamic binding.
Message-ID: <5031@aldebaran.UUCP>
Date: 16 Jan 89 15:01:59 GMT
Article-I.D.: aldebara.5031
References: <203@my2.luth.se>
Reply-To: jimp@cognos.UUCP (Jim Patterson)
Organization: Cognos Inc., Ottawa, Canada
Lines: 62