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

  1. Newsgroups: comp.lang.eiffel
  2. From: tcn@holon.demon.co.uk (Trevor Nash)
  3. Path: sparky!uunet!pipex!demon!holon!tcn
  4. Subject: Conformance 
  5. Distribution: world
  6. References: <MATTHEW.92Aug12100841@matthew.ntl02.decnet.nokia.fi>
  7. Organization: .
  8. Lines: 61
  9. Date: Thu, 13 Aug 1992 21:47:10 +0000
  10. Message-ID: <713742430snx@holon.demon.co.uk>
  11. Sender: usenet@gate.demon.co.uk
  12.  
  13.  
  14. In article <MATTHEW.92Aug12100841@matthew.ntl02.decnet.nokia.fi> matthew@ntl02.decnet.nokia.fi writes:
  15.  
  16. > 2.  A question about conformance and the like.  Here's an attempt to create
  17. > a hierarchy of classes representing employees which have a distinguishing
  18. > attribute "grade" on which they can be sorted (so we know who's first
  19. > against the wall when the revolution comes :-)
  20.  
  21. > class EMPLOYEE inherit                       class MANAGER inherit
  22. >    INT_COMPAR                                   EMPLOYEE
  23. >       rename   item as grade                       redefine grade
  24. >       redefine grade                            end
  25. >    end
  26. >                                                 feature
  27. >    feature                                         grade: INTEGER is 2
  28. >       grade: INTEGER is 1                    end
  29. > end
  30. > somewhere else...
  31. >    fred: EMPLOYEE;
  32. >    bill: MANAGER;
  33. >    !!fred; !!bill;
  34. >    if fred < bill then ...           -- *1*
  35. >    if bill < fred then ...           -- *2*
  36. > as a reminder, the declaration of infix "<" in class INT_COMPAR is:
  37. >    infix "<" (other: like Current): BOOLEAN
  38. > This leads me to ask, in the above example does *1* compile OK (as bill
  39. > conforms to EMPLOYEE) but *2* not (as fred does not conform to MANAGER)?
  40.  
  41. Correct I believe, though I too do not have an Eiffel 3 compiler
  42. (this is a thinly disguised hint to ISE ... :-)
  43. The problem is in the use of the anchor like Current.  To make it work you
  44. have to redefine "<" in EMPLOYEE to be explicitly EMPLOYEE.
  45.  
  46. > I'm afraid I don't have a compiler to check this out.  If this is indeed the
  47. > case, how in general should you implement this type of thing, e.g. a class
  48. >   SORTED_LIST[T->COMPARABLE]
  49.  
  50. You need some other class which inherits from COMPARABLE and fixes the type
  51. of the arguments to the comparison operators, then use that to constrain the 
  52. genericity.
  53.  
  54. Perhaps it would have been better if the original COMPARABLE class had a 
  55. dummy feature
  56.     other : like Current;
  57. and then defined the relations as
  58.     infix "<" (o: like other) : BOOLEAN;
  59.     etc
  60.  
  61. Then you could achieve the effect by redefining only 'other' rather than all
  62. of the relations.  Any comments from library writers?  In particular there
  63. is probably some trick to avoid having all objects contain the attribute 
  64. 'other' which is never used.
  65.  
  66. Trevor Nash
  67. tcn@holon.demon.co.uk
  68.