home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16125 < prev    next >
Encoding:
Text File  |  1992-11-11  |  1.9 KB  |  71 lines

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!haven.umd.edu!decuac!pa.dec.com!decwrl!netcomsv!ulogic!hartman
  2. From: hartman@ulogic.UUCP (Richard M. Hartman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Const Inheritance
  5. Message-ID: <573@ulogic.UUCP>
  6. Date: 11 Nov 92 22:06:34 GMT
  7. References: <Bx9vsr.4ML@slipknot.rain.com> <1992Nov09.162957.31736@Cookie.secapl.com> <BxHBGD.DtA@slipknot.rain.com>
  8. Organization: negligable
  9. Lines: 60
  10.  
  11. I modestly propose that setWidth() & setHeight() are entirely inapproprate
  12. for the heirarchy (not the single class, but the heirarchy taken as a whole).
  13.  
  14. How about:
  15.  
  16.     class Rectangle : public graphicObject
  17.         {
  18.         ...
  19.         float fWidth, fHeight;
  20.         float fRatio;
  21.         public:
  22.             virtual setHeight(float fNewHeight);
  23.             virtual setAspectRatio(float fNew);
  24.         ...
  25.         };
  26.  
  27.  
  28.     Rectangle::setHeight(float fNewHeight)
  29.     {
  30.     fHeight = fNewHeight;
  31.     fWidth    = fHeight * fRatio;
  32.     redraw();
  33.     }
  34.  
  35.     Rectangle::setAspectRatio(float newRatio) 
  36.     {
  37.     fRatio = fNew;
  38.     setHeight(fHeight);        // let the other function do the work!
  39.     }
  40.  
  41.     class Square : public graphicObject
  42.     {
  43.     ...
  44.     };
  45.  
  46.     Square::setAspectRatio(float newRatio) 
  47.     {
  48.     //- no-op for square, aspect ration initialized at 1.0
  49.     }
  50.  
  51.  
  52. There is more than one way to skin a cat, and height and aspect
  53. ratio are entirely adequate to define both rectangle and square,
  54. and you have no embarassing setSize(dim1,dim2) function hanging
  55. around with no function.  setHeight() (perhaps generalize to
  56. setSize() and inheirit from graphicObject parent...?)  does what
  57. it should in all cases.  No artificial "it sets the width when
  58. it shouldn't" to argue about.   :)
  59.  
  60.  
  61. Basically if we have such a big problem with member functions 
  62. during inheritance, perhaps you don't have the right member
  63. functions defined  :) :)
  64.  
  65.         -Richard Hartman
  66.         hartman@ulogic.COM
  67.  
  68. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  69. "There are no problems, only opportunities!"
  70. "What we have here is an insurmountable opportunity..."
  71.