home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!haven.umd.edu!decuac!pa.dec.com!decwrl!netcomsv!ulogic!hartman
- From: hartman@ulogic.UUCP (Richard M. Hartman)
- Newsgroups: comp.lang.c++
- Subject: Re: Const Inheritance
- Message-ID: <573@ulogic.UUCP>
- Date: 11 Nov 92 22:06:34 GMT
- References: <Bx9vsr.4ML@slipknot.rain.com> <1992Nov09.162957.31736@Cookie.secapl.com> <BxHBGD.DtA@slipknot.rain.com>
- Organization: negligable
- Lines: 60
-
- I modestly propose that setWidth() & setHeight() are entirely inapproprate
- for the heirarchy (not the single class, but the heirarchy taken as a whole).
-
- How about:
-
- class Rectangle : public graphicObject
- {
- ...
- float fWidth, fHeight;
- float fRatio;
- public:
- virtual setHeight(float fNewHeight);
- virtual setAspectRatio(float fNew);
- ...
- };
-
-
- Rectangle::setHeight(float fNewHeight)
- {
- fHeight = fNewHeight;
- fWidth = fHeight * fRatio;
- redraw();
- }
-
- Rectangle::setAspectRatio(float newRatio)
- {
- fRatio = fNew;
- setHeight(fHeight); // let the other function do the work!
- }
-
- class Square : public graphicObject
- {
- ...
- };
-
- Square::setAspectRatio(float newRatio)
- {
- //- no-op for square, aspect ration initialized at 1.0
- }
-
-
- There is more than one way to skin a cat, and height and aspect
- ratio are entirely adequate to define both rectangle and square,
- and you have no embarassing setSize(dim1,dim2) function hanging
- around with no function. setHeight() (perhaps generalize to
- setSize() and inheirit from graphicObject parent...?) does what
- it should in all cases. No artificial "it sets the width when
- it shouldn't" to argue about. :)
-
-
- Basically if we have such a big problem with member functions
- during inheritance, perhaps you don't have the right member
- functions defined :) :)
-
- -Richard Hartman
- hartman@ulogic.COM
-
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- "There are no problems, only opportunities!"
- "What we have here is an insurmountable opportunity..."
-