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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!ukma!darwin.sura.net!haven.umd.edu!wam.umd.edu!krc
  3. From: krc@wam.umd.edu (Kevin R. Coombes)
  4. Subject: Re: Squares and Rectangles (Re: Const Inheritance)
  5. Message-ID: <1992Nov6.213230.23801@wam.umd.edu>
  6. Sender: usenet@wam.umd.edu (USENET News system)
  7. Nntp-Posting-Host: rac2.wam.umd.edu
  8. Organization: University of Maryland, College Park
  9. References: <2762@devnull.mpd.tandem.com> <1992Nov4.165028.1273@wam.umd.edu> <561@ulogic.UUCP>
  10. Date: Fri, 6 Nov 1992 21:32:30 GMT
  11. Lines: 62
  12.  
  13. In article <561@ulogic.UUCP> hartman@ulogic.UUCP (Richard M. Hartman) writes:
  14. >In article <1992Nov4.165028.1273@wam.umd.edu> I wrote:
  15. >>
  16. >>From a mathematical point of view, there is no question about the
  17. >>relationship that should hold. Every rectangle IS-A polygon, with
  18. >>four sides and four right angles. Every square IS-A rectangle with
  19. >>four equal sides.
  20. >>
  21. >>[lots more omitted]
  22. >
  23. >In your own derivation, both rectangle and square are in turn
  24. >derived from polygon.  What generic "setsize" function would work
  25. >for it?  especially one that could be inheirited?  Is there such
  26. >a concept (not being a geometrist) as a "regular polygon", defined
  27. >as "all sides being same size"?  And where does parallelogram fit
  28. >into this?
  29.  
  30. Yes, there is a RegularPolygon (but all angles and all sides are equal).
  31. If you really want to go overboard, you might include Quadrilateral and
  32. (polygon with four sides) and Trapezoid (quadrilateral with two of its
  33. sides parallel).
  34.  
  35. >
  36. >It seems to me that a more full derivation might be:
  37. >
  38. >            Polygon
  39. >            |    |
  40. >            |    |
  41. >        RegularPolygon   Parallelogram
  42. >            |    |
  43. >            |    Rectangle
  44. >            |    |
  45. >            Square
  46. >
  47. >A "RegularPolygon" (per my guess above) might have a
  48. >single "setSideSize()" function that sets the size of
  49. >ALL sides of the figure to the same value.
  50. >
  51. >I don't think dealing with just Rectangle and Square
  52. >there IS any good, generic "size" type of function that
  53. >you can rely on.  Especially if you do strict IS-A 
  54. >derivation using the mathematical definiations.
  55. >
  56. >However, as someone pointed out, it is possible
  57. >to say: "a Rectangle IS-A Square that is separately
  58. >adjustable in 2 dimensions".  (Perhaps this makes more
  59. >sense if you are an engineer than if you are a 
  60. >mathematician...)
  61. >
  62. >Then Rectangle would inherit Square's setSize(int)
  63. >member function, and also implement it's own
  64. >setSize(int,int) function as well.
  65. >
  66.  
  67. Overloading SetSize() to take more parameters is an intriguing idea....
  68.  
  69. But I would be very unhappy inheriting Rectangle from Square. The problem
  70. arises when you have a Square *. The Square class assures you that it
  71. will have equal sides. It hardly seems fair for a derived class to
  72. weaken that assertion.
  73.  
  74. Kevin Coombes <krc@math.umd.edu>
  75.