Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!mucs!logitek!hrc63!mrcu!paj From: paj@mrcu (Paul Johnson) Newsgroups: comp.lang.eiffel Subject: Re: a problem in programming with Eiffel Message-ID: <798@puck.mrcu> Date: 23 Jan 91 14:54:40 GMT References: <20022@hydra.gatech.EDU> Reply-To: paj@uk.co.gec-mrc (Paul Johnson) Organization: GEC-Marconi Research Centre, Great Baddow, UK Lines: 47 Summary: Expires: Sender: Followup-To: >I have a curious problem. I am writing an application in Eiffel that >makes use of the graphics library. In particular, I need to use >objects that are similar to the class COMPLEX_FIG in the library, yet >a little different from it. My class is similar in the sense that it >is to have a list of figures and the whole list has to behave like a >figure. But it is different because the figures in the list are >really going to be a special type of figure that is a descendant of >class FIGURE. >At first I thought that I could make my class a descendent of the class >COMPLEX_FIG and proceed from there. This is the most natural solution. >However, it turns out that COMPLEX_FIG inherits from FIG and LINKED_LIST, >and the generic parameter of the linked list is FIGURE. This causes a >problem because I need the generic parameter to be something that is >capable of responding to feature calls of my special figure. This >seemingly cannot be done because the generic parameter is hardwired, >so to speak, to the class FIGURE. >My question is: short of duplicating the code for COMPLEX_FIG with the >generic parameter of the inherited linked list now as my special figure, >is there any other better way to solve the problem? >I suspect that the problem is not just a matter of good library design, >but also a problem of language design. Could someone enlighten me? I will try, although I have not checked the following against the Eiffel type rules. Hence it may not work. When you produce your child of COMPLEX_FIG (say, MY_COMPLEX_FIG, although this would be a bad name in practice) you should say `redefine first; rename first as old_first' and then define `first' as being of the appropriate type and returning (using the reverse assignment operator `?=') the value of `old_first'. All the other features of LINKED_LIST are `like first', so this will make the change to all of them. This is the first time I have really appreciated the utility of `like'. If this does not work then use the reverse assignment operator outside of COMPLEX_FIG to undo the type loss before applying your features. Paul. -- Paul Johnson UUCP: !mcvax!ukc!gec-mrc!paj --------------------------------!-------------------------|------------------- GEC-Marconi Research is not | Telex: 995016 GECRES G | Tel: +44 245 73331 responsible for my opinions. | Inet: paj@uk.co.gec-mrc | Fax: +44 245 75244