home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / eiffel / 1317 < prev    next >
Encoding:
Text File  |  1992-11-18  |  2.9 KB  |  89 lines

  1. Path: sparky!uunet!mcsun!julienas!cix!irit!iris4!mouli
  2. From: mouli@iris4irit.fr (Richard MOULI)
  3. Newsgroups: comp.lang.eiffel
  4. Subject: Re: repeated inheritance and renaming
  5. Message-ID: <2632@irit.irit.fr>
  6. Date: 18 Nov 92 22:35:16 GMT
  7. Sender: usenet@irit.fr
  8. Lines: 75
  9.  
  10. --------------------------------------------------------------------------------
  11. From: ambuj@ucsb.edu (Singh)
  12.  
  13.  
  14. I have the following question regarding repeated 
  15. inheritance and renaming in Eiffel.
  16.  
  17. Suppose I have the following classes:
  18.  
  19.             class R
  20.  
  21.             feature
  22.                 x:integer;
  23.                 f is do
  24.                     x := x+1;
  25.                 end;
  26.             end
  27.  
  28.  
  29. class A            class B            class C
  30. inherit            inherit            inherit 
  31.   R redefine f;          R rename x as xB      R
  32. feature            end            end
  33.   f is do
  34.     x := x + 2;
  35.   end;
  36. end
  37.  
  38.             class S
  39.             inherit 
  40.                 A rename f as fA;
  41.                 B rename f as fB;
  42.                 C;
  43.             feature
  44.                 Create is
  45.                     do
  46.                         fB;
  47.                         io.putint(xB); io.new_line;
  48.                     end;
  49.             end
  50.  
  51. Assume that class S is the ``root'' class of the system.
  52. Upon activation of S.create,
  53. I would have expected procedure fB to update xB and
  54. the subsequent print statement to print 1.
  55. However, it seems that fB updates x instead of xB
  56. and 0 is the value printed.
  57. I also find that if S does not inherit from A then the
  58. expected happens and 1 gets printed.
  59. What am I missing?  Is this a problem with the installation
  60. of Eiffel?
  61.  
  62. Thanks.
  63.  
  64. Ambuj Singh
  65. Dept. of Computer Science
  66. University of California
  67. Santa Barbara, CA 93106
  68. ambuj@cs.ucsb.edu
  69.  
  70. --------------------------------------------------------------------------------
  71.  
  72.  
  73. I am PhD student and I do all my work whith Eiffel. I have already met some problems with repeated inheritance and renaming. I know this : in the actual implementation of the Eiffel compiler, an object is like an array of fields. That's mean when you reference a field by its name, the compiler translates by the access to the field-number item in the array. In your problem, the field named `x' in the class R is the i_th item of the array and the routine f of the same class uses this number to update the fie
  74.  
  75.  
  76.  
  77.  
  78. ld `x'.
  79.  
  80. The renaming and the repeating inheritance of class R through the class A, B and C introduce the duplication of the field `x' of R as fields `x' (from A) and `xB' (from B) and the duplication of the routine `f' of R as routines fA (from A), fB (from B) and f (from R through C). Now you have two fields (`x' and `xB' - two elements in the array) but the routines f, fA, fB which use the field `x' still acces to the same i_th element in the array.
  81.  
  82. I think if you reverse the inheritance clauses of class A and B, you will have the expected result but the routines f and fA will update also the field `xB'.
  83.  
  84. May be, you will have what you want by renaming the field `x' of the class B in the inheritance clause of this class in the class S because the compiler will change the number of the item used by the routine fB.
  85.  
  86. Richard MOULI IRIT-UPS Toulouse (FRANCE)
  87.  
  88. mouli@irit.fr
  89.