[comp.lang.eiffel] Renaming and Repeated Inheritance

db@lfcs.ed.ac.uk (Dave Berry) (03/11/90)

I have a question about the Eiffel rule for determining whether a repeatedly
inherited feature is shared.

As stated in OOSC the rule says that if a class C inherits a feature f
twice without it being renamed on either inheritance path, then f
refers to the same object.  The problem with this is that f might be
renamed in parent classes for reasons particular to those classes -
such as avoiding a name clash or choosing a name more appropriate to
that class.  I believe that control over whether f is inherited twice
or is shared should rest in the class C.

When the renaming is done in the class C itself, the current rule
works fine.  Consider the following rewrite of the example from
OOSC: 
			class DRIVER
			  feature address

	class FRANCE_DRIVER		class US_DRIVER
	  inherit DRIVER		  inherit DRIVER

	  	    class FRANCE_US_DRIVER
		      inherit FRANCE_DRIVER
			rename address as france_address
		      inherit US_DRIVER
			rename address as us_address

Clearly two addresses are desired, or the programmer wouldn't have
renamed the attributes of the parent classes.

What of the case when the feature is renamed in the parent classes,
as in the original version of the above example, but we want it to be
shared in FRANCE_US_DRIVER?  (The example isn't appropriate in this case,
but the general point can still be asked.)  If the two parent features
are renamed to the same name in FRANCE_US_DRIVER, will the original
feature be shared?

			class DRIVER
			  feature address

	class FRANCE_DRIVER		class US_DRIVER
	  inherit DRIVER		  inherit DRIVER
	    rename address		    rename address
	    as france_address		    as us_address

	  	    class FRANCE_US_DRIVER
		      inherit FRANCE_DRIVER
			rename france_address as address
		      inherit US_DRIVER
			rename us_address as address

I think that this should be possible.

A slightly different method of achieving the same result would be to use
an explicit "sharing" clause.  This has the advantage that the sharing
would be more obvious to someone reading the class.

	  	    class FRANCE_US_DRIVER
		      inherit FRANCE_DRIVER, US_DRIVER
		      sharing us_address and france_address

If you want a single name for the feature in FRANCE_US_DRIVER, you
could add an "as" clause, e.g.

		      sharing us_address and france_address
		        as address

Comments?

 Dave Berry, LFCS, Edinburgh Uni.      db%lfcs.ed.ac.uk@nsfnet-relay.ac.uk

"The thought of someone sharing one's own preferences without also sharing
 one's aversions strikes most people as utterly inconceivable." - C. A. Tripp.