Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!bony1!richieb From: richieb@bony1.bony.com (Richard Bielak) Newsgroups: comp.lang.eiffel Subject: Re: A question on generic parameters Message-ID: <1991Apr15.131054.110@bony1.bony.com> Date: 15 Apr 91 13:10:54 GMT References: <1203@nikhefh.nikhef.nl> Reply-To: richieb@bony1.UUCP (Richard Bielak) Organization: Bank of New York Lines: 45 In article <1203@nikhefh.nikhef.nl> a38@nikhefh.nikhef.nl (James Barr) writes: [...] >I noticed that you could only do the bare minimum of operations >on generic class parameters, which seemed a bit limiting. >In the case of an ordered list class you would need a class >parameter that could support a comparision function, but there >seems no way of doing this. > [...] > >class OrderedList [T heir of Ordered] > ... > >deferred class Ordered > -- make this an heir of any class/type whose instances/values > -- can be ordered. > export compare; > compare (a,b : Ordered) : Boolean > ... > Although not discussed in "Object Oriented Software Construction", Eiffel does support such constructs. This feature is called "constrained genericity". Using the actual syntax, your example would be written as: class OrderedList [ T -> COMPARABLE ] is [...whatever...] Then within this class you could use any routine or attribute from COMPARABLE on things declared with type T. Hope this answers your question. ...richie -- *-----------------------------------------------------------------------------* | Richie Bielak (212)-815-3072 | Programs are like baby squirrels. Once | | Internet: richieb@bony.com | you pick one up and handle it, you can't | | Bang: uunet!bony1!richieb | put it back. The mother won't feed it. |