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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!tessi!eaglet!slipknot!robert
  3. From: robert@slipknot.rain.com (Robert Reed)
  4. Subject: Re: Const Inheritance
  5. Message-ID: <Bx9vsr.4ML@slipknot.rain.com>
  6. Reply-To: robert@slipknot.rain.com.UUCP (Robert Reed)
  7. Organization: Home Animation Ltd.
  8. References: <1992Oct29.173017.109790@Cookie.secapl.com> <BwwvMw.DDC@slipknot.rain.com> <1992Nov05.165658.34729@Cookie.secapl.com>
  9. Date: Fri, 6 Nov 1992 02:19:38 GMT
  10. Lines: 102
  11.  
  12. In article <1992Nov05.165658.34729@Cookie.secapl.com> frank@Cookie.secapl.com (Frank Adams) writes:
  13. |In article <BwwvMw.DDC@slipknot.rain.com> robert@slipknot.rain.com.UUCP (Robert Reed) writes:
  14. |>I have not violated the intended semantics, I have generalized them, within
  15. |>reasonable confines of the language.
  16. |
  17. |Since I'm giving the example, I know what the intended semantics are.  If I
  18. |am defining the Rectangle class in a context where I can make assertions, I
  19. |will assert that setWidth does not change the height, and vice versa.  This
  20. |is the intended semantics, even though the assertions are not available in
  21. |the language.
  22.  
  23. Well, EXCUSE ME!  It's true that you as the designer define the intended
  24. semantics, but it is also true that I as a potential user will, in the absence
  25. of further documentation, assume a semantic content based on the cues I get,
  26. such as function names.  To me, a square still has a width and a height, but
  27. they just happen to be constrained to be the same.  If C++ had declarative
  28. assertions, I would expect that placing an assertion on the width and height of
  29. a Square should not affect its base Rectangle class.
  30.  
  31. |void setDimensions(Rectangle& r, int x, int y) {
  32. |    r.setWidth(x);
  33. |    r.setWidth(y);
  34. |}
  35. |
  36. |I expect this function to work: after it is called, r.width() should be x,
  37. |and r.height() should be y.
  38.  
  39. (I believe the 2nd setWidth() should be a setHeight().)   I see nothing in my
  40. counter-proposal which would deny the operation of this function.
  41.  
  42. |>|>  Alternatively, you could make Rectangle a subclass of
  43. |>|>Square, define a setPrimaryDimension(int) for Square and add
  44. |>|>setSecondaryDimension(int) for the specialized Rectangle class.
  45. |
  46. |There is another problem with this, if I decide to generalize a bit: I may
  47. |want to define:
  48. |
  49. |    template<class WidthT, class HeightT>
  50. |    class Rectangle {...}
  51. |
  52. |    template<class SideT>
  53. |    class Square : public Rectangle<SideT, SideT> {...}
  54. |
  55. |In this case, Rectangle cannot inherit from Square; it would have to change
  56. |the types of the instance variables.  This is not an altogether artificial
  57. |example; I worked on a word processor (not written in an O.O. language) in
  58. |which horizontal and vertical distances were expressed in different units.
  59. |(This program had no use for squares, however.)
  60.  
  61. If your intent is to use Squares on a system with different horizontal and
  62. vertical dimensions, then even your scheme of Const Inheritance doesn't solve
  63. the problem.  You still have to deal with how to specify a square.  Is it
  64. expressed in horizontal or vertical units?  Or both?  If you're going to
  65. constrain the problem so as to exclude alternate solutions, make sure your own
  66. solution still works.
  67.  
  68. |>| I don't mean to imply that this construct is necessary to create a usable
  69. |>| class hierarchy; just that it seems to me to produce a cleaner
  70. |>| specification thereof.
  71. |>
  72. |>That's not all I said in my last note.  My claim was that your language
  73. |>enhancement is a partial feature which muddies the specification (by creating
  74. |>anartificial restriction on inherited virtual functions to those that are
  75. |>declared const), thus complicating the inheritance rules while providing no
  76. |>clear advantage.
  77. |
  78. |See my followup to my original article; it provides a point of view under
  79. |which the restriction seems natural.
  80.  
  81. I have read through your followup, and it doesn't fix what I see as an
  82. artificial constraint imposed by your syntax.  If I understand your basic
  83. postulate, it is: there are certain subclasses of desired classes that inherit
  84. functions from their bases that violate closure of the subclasses (i.e.,
  85. application of these functions result in objects which violate assertions of
  86. the subclass) and that to solve this problem we should permit the subclasses to
  87. exclude ANY function that modifies object data, thereby preventing the
  88. inclusion of closure-violating functions.
  89.  
  90. My claim is still that this a brutish approach to a problem that has been
  91. solved in many other languages, such as Modula-3, Eiffel, etc.; that is,
  92. selective inheritance.  As such, const inheritance is a partial feature.  In
  93. the example we have been abusing, all you really want to restrict is CERTAIN
  94. geometry modifying functions--not even all of them.  For example, shouldn't I
  95. be able to define a Rectangle::setScale() function which could be inherited by
  96. Square?  It would change variables but not affect the geometric constraints
  97. you've expressed concern about.  How about a Rectangle::setBoundaryColor()
  98. function?  This is a nongeometric function and so should be equally usable by
  99. Rectangles and Squares.
  100.  
  101. My problem with your proposal is not that it would not provide some useful
  102. extention to current syntax.  My concern is that your solution only covers a
  103. small subset of the problem domain, and as such must be considered a partial
  104. feature, a potential source of more frustration than facility.
  105. ________________________________________________________________________________
  106. Robert Reed            Home Animation Ltd.        503-656-8414
  107. robert@slipknot.rain.com    5686 First Court, West Linn, OR 97068
  108.  
  109. We offer the party as a big tent.  How we do that within the platform, the
  110. preamble to the platform, or whatnot, that remains to be seen.  But that
  111. message will have to be articulated with great clarity.
  112. --Dan Quayle, interview with the Washington Post, December 1989
  113. ________________________________________________________________________________
  114.