Xref: utzoo comp.lang.eiffel:1393 comp.object:2534 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!fuug!news.funet.fi!tukki.jyu.fi!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.lang.eiffel,comp.object Subject: Re: Inheritance and Information Hiding Message-ID: <1991Feb8.133003.25129@tukki.jyu.fi> Date: 8 Feb 91 13:30:03 GMT References: <1991Feb5.130359.9735@bellcore.bellcore.com> <1991Feb6.045542.791@visix.com> <1991Feb7.151212.25200@bony1.bony.com> Reply-To: sakkinen@jytko.jyu.fi (Markku Sakkinen) Organization: University of Jyvaskyla, Finland Lines: 48 In article <1991Feb7.151212.25200@bony1.bony.com> richieb@bony1.UUCP (Richard Bielak) writes: >In article <1991Feb6.045542.791@visix.com> adam@visix.com (Adam Kao) writes: >> >[...lots of stuff deleted...] > >>We know how to add vertices to POLYGONs. I think it ridiculous to say >>we do not know how to add vertices to RECTANGLEs. The problem is, >>adding a vertex to a RECTANGLE gives us something that is not a >>RECTANGLE. >> >>I do not see this as a problem. Why do we expect that all operations >>on an Object must be closed over its Class? >> > >Perhaps the "add_vertex" routine should be a function? How about >this: > > add_vertex : POLYGON is > do > -- whatever > end; > > >Then if "r" is a RECTANGLE, we can call "r.add_vertex" and get back >an object that is not a RECTANGLE. This looked at first like a very good solution to me. However, it fits best if the interfaces of Polygon and other related classes are even in general defined in a "functional" fashion: i.e. modifying operations do not modify the "self" object but return a new object. If some operations modify the object itself and others return a new object instead, the interface is very inconsistent. The functional approach has its severe drawbacks, too. Suppose that there are several references from other objects to this geometric object (initially a rectangle). If the intended semantics is that the sharing relationship between these references is maintained (which would be the typical case), one would need to have back pointers to all those other objects in order to make them refer to the modified polygon. Markku Sakkinen Department of Computer Science and Information Systems University of Jyvaskyla (a's with umlauts) PL 35 SF-40351 Jyvaskyla (umlauts again) Finland SAKKINEN@FINJYU.bitnet (alternative network address)