Xref: utzoo comp.lang.c++:3370 comp.lang.eiffel:198 comp.lang.smalltalk:1087 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!ames!purdue!gatech!ncsuvx!mcnc!thorin!jason!tuck From: tuck@jason.cs.unc.edu (Russ Tuck) Newsgroups: comp.lang.c++,comp.lang.eiffel,comp.lang.smalltalk Subject: Re: Use of inheritance for classification? Message-ID: <8166@thorin.cs.unc.edu> Date: 19 May 89 02:29:49 GMT References: <30582@apple.Apple.COM> <6365@brunix.UUCP> <6685@brunix.UUCP> Sender: news@thorin.cs.unc.edu Reply-To: tuck@jason.UUCP (Russ Tuck) Organization: University Of North Carolina, Chapel Hill Lines: 45 Let me say first that I agree with the main points of the article quoted below. However, the particular example chosen can be changed to avoid the problem and better correspond to "reality". In article <6685@brunix.UUCP> bpe@cs.brown.edu (Page Elmore) writes: >If you have the types such as: > > Type Car > ^ Property: color: allColors (type with instances of all colors) > | Method: Paint(newColor: allColors) > | > | > Type Honda CRX (inherits from Car) > Property color: blueBlack (type with blue and black instances) > >where Type Car ... >also has a method Paint which takes as its argument an instance of >allcolors. Somewhere in the implementation of paint it sets the color of >the car to the newly painted color -- an instance of allColors. Now >what happens when someone invokes the Paint method with red as the argument >on members of a set of Cars, some of which happen to also be Honda CRX's >(this is invoking the rule that instances of the subtype are also instances >of the supertype)? The Paint method will fail on those objects which are >Honda CRX's. If you have a real Honda CRX and pay a body shop to paint it red, what happens? Do they say "I'm sorry, we can't do that. Honda CRXs can only be black and blue"? No, they paint it red and you have an unusual red Honda CRX that can't be bought directly from Honda. I think the most natural way to define Honda CRX above is to give it a constructor that enforces the restriction that all Honda CRXs are *initially* black or blue. The color property is inherited unchanged (not restricted). >No matter how you do it, constraint of any of the signatures of a supertype >in the subtype may "break" the implementation of the supertype or anything >written to work on instances of the supertype. Good point. -- Russ Tuck internet: tuck@cs.unc.edu Computer Science Dept., Sitterson Hall csnet: tuck@unc University of North Carolina uucp: ...!mcnc!unc!tuck Chapel Hill, NC 27599-3175, USA Phone: (919) 962-1755 or 962-1932