home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.eiffel
- From: tcn@holon.demon.co.uk (Trevor Nash)
- Path: sparky!uunet!pipex!demon!holon!tcn
- Subject: Conformance
- Distribution: world
- References: <MATTHEW.92Aug12100841@matthew.ntl02.decnet.nokia.fi>
- Organization: .
- Lines: 61
- Date: Thu, 13 Aug 1992 21:47:10 +0000
- Message-ID: <713742430snx@holon.demon.co.uk>
- Sender: usenet@gate.demon.co.uk
-
-
- In article <MATTHEW.92Aug12100841@matthew.ntl02.decnet.nokia.fi> matthew@ntl02.decnet.nokia.fi writes:
-
- > 2. A question about conformance and the like. Here's an attempt to create
- > a hierarchy of classes representing employees which have a distinguishing
- > attribute "grade" on which they can be sorted (so we know who's first
- > against the wall when the revolution comes :-)
-
- >
- > class EMPLOYEE inherit class MANAGER inherit
- > INT_COMPAR EMPLOYEE
- > rename item as grade redefine grade
- > redefine grade end
- > end
- > feature
- > feature grade: INTEGER is 2
- > grade: INTEGER is 1 end
- > end
- >
- > somewhere else...
- >
- > fred: EMPLOYEE;
- > bill: MANAGER;
- >
- > !!fred; !!bill;
- > if fred < bill then ... -- *1*
- > if bill < fred then ... -- *2*
- >
- > as a reminder, the declaration of infix "<" in class INT_COMPAR is:
- > infix "<" (other: like Current): BOOLEAN
- >
- > This leads me to ask, in the above example does *1* compile OK (as bill
- > conforms to EMPLOYEE) but *2* not (as fred does not conform to MANAGER)?
-
- Correct I believe, though I too do not have an Eiffel 3 compiler
- (this is a thinly disguised hint to ISE ... :-)
- The problem is in the use of the anchor like Current. To make it work you
- have to redefine "<" in EMPLOYEE to be explicitly EMPLOYEE.
-
- > I'm afraid I don't have a compiler to check this out. If this is indeed the
- > case, how in general should you implement this type of thing, e.g. a class
- > SORTED_LIST[T->COMPARABLE]
-
- You need some other class which inherits from COMPARABLE and fixes the type
- of the arguments to the comparison operators, then use that to constrain the
- genericity.
-
- Perhaps it would have been better if the original COMPARABLE class had a
- dummy feature
- other : like Current;
- and then defined the relations as
- infix "<" (o: like other) : BOOLEAN;
- etc
-
- Then you could achieve the effect by redefining only 'other' rather than all
- of the relations. Any comments from library writers? In particular there
- is probably some trick to avoid having all objects contain the attribute
- 'other' which is never used.
-
- Trevor Nash
- tcn@holon.demon.co.uk
-