home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!haven.umd.edu!wam.umd.edu!krc
- From: krc@wam.umd.edu (Kevin R. Coombes)
- Subject: Re: Squares and Rectangles (Re: Const Inheritance)
- Message-ID: <1992Nov21.012816.19421@wam.umd.edu>
- Sender: usenet@wam.umd.edu (USENET News system)
- Nntp-Posting-Host: rac1.wam.umd.edu
- Organization: University of Maryland, College Park
- References: <1992Nov19.171731.23740@ucc.su.OZ.AU> <1992Nov20.012340.19437@fcom.cc.utah.edu>
- Date: Sat, 21 Nov 1992 01:28:16 GMT
- Lines: 46
-
- In article <1992Nov20.012340.19437@fcom.cc.utah.edu> val@news.ccutah.edu (Val Kartchner) writes:
- >In article <721507350snx@trmphrst.demon.co.uk> nikki@trmphrst.demon.co.uk writes:
- >>In article <1992Nov4.165028.1273@wam.umd.edu> krc@wam.umd.edu (Kevin R. Coombes) writes:
- >>> From a mathematical point of view, there is no question about the
- >>> relationship that should hold. Every rectangle IS-A polygon, with
- >>> four sides and four right angles. Every square IS-A rectangle with
- >>> four equal sides.
- >
- >>I think our problem here is that we have two separate meanings of "is-a".
- >>In the geometrical sense, any particular Square "is-a" Rectangle.
- >
- >The mathematical heirarchy is inverted for OO. Perhaps the "is-a" relationship
- >should be "is-a-...-with-additions". For example:
- >
- > shape // Abstract base class
- > ^
- > |
- > square // base class
- > ^
- > |
- > rectangle // a square with both dimensions adjustable
- > ^
- > |
- > parallelogram // a rectangle with an adjustable angle
- > [ more levels omitted...]
- >There would also be other branches in the 'shape' heirarchy, but this
- >illustrates the principle.
- >
-
- I don't understand some of the details of this hierarchy. I particularly
- don't understand how to reuse certain code. What methods does square have?
- Which are overloaded in Rectangle? Which are virtual? Which data methods
- do they have? For example, a Square probably has a location (specified by
- its center, or its upper left, or any convention you like) and a side length.
- It should have a constraint (though these are unenforcable in the current
- language---interested parties should look at A++) that keeps it square.
- Some of the methods you might like to have are the ability to intersect
- it with other shapes, or to display it. If you intersect two squares, the
- best you can hope to get is a rectangle (I'll continue to assume the sides
- are aligned, to keep things simple). Where do you put the method? Is it a
- virtual method in square? A pure virtual method? What happens when you want
- to intersct two rectangles? Is there any way to write this hierarchy so that
- you can reuse both the code to intersect (or display) shapes and the code
- to modify dimensions?
-
- Kevin Coombes <krc@math.umd.edu>
-