home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!ukma!darwin.sura.net!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: <1992Nov6.213230.23801@wam.umd.edu>
- Sender: usenet@wam.umd.edu (USENET News system)
- Nntp-Posting-Host: rac2.wam.umd.edu
- Organization: University of Maryland, College Park
- References: <2762@devnull.mpd.tandem.com> <1992Nov4.165028.1273@wam.umd.edu> <561@ulogic.UUCP>
- Date: Fri, 6 Nov 1992 21:32:30 GMT
- Lines: 62
-
- In article <561@ulogic.UUCP> hartman@ulogic.UUCP (Richard M. Hartman) writes:
- >In article <1992Nov4.165028.1273@wam.umd.edu> I wrote:
- >>
- >>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.
- >>
- >>[lots more omitted]
- >
- >In your own derivation, both rectangle and square are in turn
- >derived from polygon. What generic "setsize" function would work
- >for it? especially one that could be inheirited? Is there such
- >a concept (not being a geometrist) as a "regular polygon", defined
- >as "all sides being same size"? And where does parallelogram fit
- >into this?
-
- Yes, there is a RegularPolygon (but all angles and all sides are equal).
- If you really want to go overboard, you might include Quadrilateral and
- (polygon with four sides) and Trapezoid (quadrilateral with two of its
- sides parallel).
-
- >
- >It seems to me that a more full derivation might be:
- >
- > Polygon
- > | |
- > | |
- > RegularPolygon Parallelogram
- > | |
- > | Rectangle
- > | |
- > Square
- >
- >A "RegularPolygon" (per my guess above) might have a
- >single "setSideSize()" function that sets the size of
- >ALL sides of the figure to the same value.
- >
- >I don't think dealing with just Rectangle and Square
- >there IS any good, generic "size" type of function that
- >you can rely on. Especially if you do strict IS-A
- >derivation using the mathematical definiations.
- >
- >However, as someone pointed out, it is possible
- >to say: "a Rectangle IS-A Square that is separately
- >adjustable in 2 dimensions". (Perhaps this makes more
- >sense if you are an engineer than if you are a
- >mathematician...)
- >
- >Then Rectangle would inherit Square's setSize(int)
- >member function, and also implement it's own
- >setSize(int,int) function as well.
- >
-
- Overloading SetSize() to take more parameters is an intriguing idea....
-
- But I would be very unhappy inheriting Rectangle from Square. The problem
- arises when you have a Square *. The Square class assures you that it
- will have equal sides. It hardly seems fair for a derived class to
- weaken that assertion.
-
- Kevin Coombes <krc@math.umd.edu>
-