home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / eiffel / 1063 < prev    next >
Encoding:
Text File  |  1992-08-13  |  3.6 KB  |  96 lines

  1. Newsgroups: comp.lang.eiffel
  2. Path: sparky!uunet!psinntp!bony1!richieb
  3. From: richieb@bony1.bony.com (Richard Bielak)
  4. Subject: Re: Conformance
  5. Message-ID: <1992Aug14.025139.13055@bony1.bony.com>
  6. Organization: multi-cellular
  7. References: <MATTHEW.92Aug12100841@matthew.ntl02.decnet.nokia.fi>
  8. Date: Fri, 14 Aug 92 02:51:39 GMT
  9. Lines: 85
  10.  
  11. In article <MATTHEW.92Aug12100841@matthew.ntl02.decnet.nokia.fi> matthew@ntl02.decnet.nokia.fi (Matthew Faupel) writes:
  12. >Nobody answered this the first time round, so I'll try again.  There must be
  13. >at least one *real* Eiffel user who reads this conference and can answer the
  14. >question (as opposed to all us kibbitzers :-)
  15. >
  16.  
  17. Well, I'm a *real* Eiffel user, although, I'm still using Eiffel 2.3.
  18. I'll try to answer your question.
  19.  
  20. >Here it is again:
  21. >
  22. >2.  A question about conformance and the like.  Here's an attempt to create
  23. >a hierarchy of classes representing employees which have a distinguishing
  24. >attribute "grade" on which they can be sorted (so we know who's first
  25. >against the wall when the revolution comes :-)
  26. >
  27. >class EMPLOYEE inherit                       class MANAGER inherit
  28. >   INT_COMPAR                                   EMPLOYEE
  29. >      rename   item as grade                       redefine grade
  30. >      redefine grade                            end
  31. >   end
  32. >                                                feature
  33. >   feature                                         grade: INTEGER is 2
  34. >      grade: INTEGER is 1                    end
  35. >end
  36. >
  37. >somewhere else...
  38. >
  39. >   fred: EMPLOYEE;
  40. >   bill: MANAGER;
  41. >
  42. >   !!fred; !!bill;
  43. >   if fred < bill then ...           -- *1*
  44. >   if bill < fred then ...           -- *2*
  45. >
  46. >as a reminder, the declaration of infix "<" in class INT_COMPAR is:
  47. >   infix "<" (other: like Current): BOOLEAN
  48. >
  49. >This leads me to ask, in the above example does *1* compile OK (as bill
  50. >conforms to EMPLOYEE) but *2* not (as fred does not conform to
  51. MANAGER)?
  52.  
  53. You are correct *2* will not compile, as EMPLOYEE does not conform
  54. to MANAGER (hey, I like the sound of this :-)).
  55.  
  56. >I'm afraid I don't have a compiler to check this out.  If this is indeed the
  57. >case, how in general should you implement this type of thing, e.g. a class
  58. >  SORTED_LIST[T->COMPARABLE]
  59. >where in fact the members of the list are hetrogeneous objects that conform
  60. >to COMPARABLE, but not necessarily to each other?  If it isn't the case,
  61. >what have I misunderstood?
  62. >
  63.  
  64. There is no problem in implementing SORTED_LIST [EMPLOYEE]. Now you
  65. can put anything in the list that conforms to EMPLOYEE. Since MANAGER
  66. inherits from EMPLOYEE, it can be added to the list, as the routine
  67. that adds elements is declared as:
  68.  
  69.      put (new_item : EMPLOYEE);
  70.  
  71. As far as the comparisons within the SORTED_LIST code, everything here
  72. is declared of static type EMPLOYEE (actually "T", which is replaced
  73. by "EMPLOYEE" to be more precise). So within SORTED_LIST only things
  74. declared as EMPLOYEE are compared.
  75.  
  76. However, to a variable of type EMPLOYEE you can attach a reference
  77. of an object that conforms to EMPLOYEE, eg. object of type MANAGER.
  78. From then on, dynamic binding takes care of invocation of the correct
  79. "grade" to perform comparisons.
  80.  
  81.  
  82. I hope this answers your question. 
  83.  
  84. ...richie
  85.  
  86. P.S. I didn't respond sooner, since I'm on vacation :-).
  87.  
  88. P.P.S. You cannot redefine an atttribute to be a constant. 
  89.  
  90.  
  91. -- 
  92. * Richie Bielak   (212)-815-3072   | "Your brain is a liquid-cooled parallel  *
  93. * Internet:       richieb@bony.com | super-computer". He pointed to his nose, *
  94. * Bang {uupsi,uunet}!bony1!richieb | "This is the fan."                       *
  95. *    - Strictly my opinions -      |                     - David Chudnovsky - *
  96.