Path: utzoo!utgpu!watmath!clyde!att!osu-cis!killer!mit-eddie!husc6!bunny!dcr0 From: dcr0@bunny.UUCP (David Robbins) Newsgroups: comp.lang.eiffel Subject: Possible Inheritance Anomaly Keywords: inheritance Message-ID: <6416@bunny.UUCP> Date: 9 Jan 89 17:32:08 GMT Organization: GTE Laboratories, Waltham, MA Lines: 70 I've come across an apparent anomaly in the Eiffel inheritance mechanism. I'm not really sure if this is a bug or if it is simply that Eiffel does not behave in the way that I would expect. It has to do with renaming an inherited feature, and is perhaps best illustrated by example. So here goes: I have three classes named ROOT_CLASS, A, and B, defined as follows: root_class.e -- class ROOT_CLASS inherit STD_FILES feature an_a: A; a_b: B; b_invoked_as_a: A; Create is do an_a.Create; a_b.Create; b_invoked_as_a := a_b; putstring("Calling A.f1: "); an_a.f1; putstring("Calling A.f2: "); an_a.f2; putstring("Calling B.f1: "); a_b.f1; putstring("Calling B.f2: "); a_b.f2; putstring("Calling B.f3 (which is really A.f1): "); a_b.f3; putstring("Calling B.f1 through A's interface: "); b_invoked_as_a.f1; putstring("Calling B.f2 through A's interface: "); b_invoked_as_a.f2 end end a.e -- class A export f1, f2 inherit STD_FILES feature f1 is do putstring("I am A.f1"); new_line end; f2 is do putstring("I am A.f2"); new_line end end b.e -- class B export f1, f2, f3 inherit A rename f1 as f3 redefine f2 feature f1 is do putstring("I am B.f1"); new_line end; f2 is do putstring("I am B.f2"); new_line end end Results of Execution -- Calling A.f1: I am A.f1 Calling A.f2: I am A.f2 Calling B.f1: I am B.f1 Calling B.f2: I am B.f2 Calling B.f3 (which is really A.f1): I am A.f1 Calling B.f1 through A's interface: I am A.f1 Calling B.f2 through A's interface: I am B.f2 The apparent anomaly is what happens when B.f1 is called through A's interface. I would have expected that regardless of what interface is used, a call to B.f1 would execute the feature that B has defined as its f1. Yet here, when B is called through A's interface, the f1 feature executed is that which A defined as f1! I suppose that some argument could be made that this is appropriate behavior, but it surely is contrary to what it is done in other object-oriented languages. I wonder what Bertrand Meyer intended the behavior to be in this case? Is this a bug or is it by design? Do you comp.lang.eiffel readers have an opinion as to whether this is or is not a bug? -- Dave Robbins GTE Laboratories Incorporated drobbins@gte.com 40 Sylvan Rd. ...!harvard!bunny!drobbins Waltham, MA 02254