home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16007 < prev    next >
Encoding:
Text File  |  1992-11-09  |  4.2 KB  |  89 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: <BxHBGD.DtA@slipknot.rain.com>
  6. Reply-To: robert@slipknot.rain.com.UUCP (Robert Reed)
  7. Organization: Home Animation Ltd.
  8. References: <1992Nov05.165658.34729@Cookie.secapl.com> <Bx9vsr.4ML@slipknot.rain.com> <1992Nov09.162957.31736@Cookie.secapl.com>
  9. Date: Tue, 10 Nov 1992 02:41:01 GMT
  10. Lines: 77
  11.  
  12. In article <1992Nov09.162957.31736@Cookie.secapl.com> frank@Cookie.secapl.com (Frank Adams) writes:
  13. |>I see nothing in my counter-proposal which would deny the operation of this
  14. |>function.
  15. |
  16. |But I can do the following:
  17. |
  18. |    Square s;
  19. |    setDimensions(s, 2, 3);
  20. |
  21. |This does not work; after the call, the width will not be 2.  (Of course,
  22. |presented this baldly, I would not expect it to work; but I could be passing
  23. |s to some other function which took a rectangle argument, and called
  24. |setDimensions on it; the resulting bug is quite subtle.)
  25.  
  26. My point remains that we can design conventions to deal with overspecification
  27. problems like this under the auspices of the current language.  Your
  28. alternative would be a bludgeon that would deny the access to ANY object
  29. modification functions.
  30.  
  31. |>|There is another problem with this, if I decide to generalize a bit: I may
  32. |>|want to define:
  33. |>|
  34. |>|    template<class WidthT, class HeightT>
  35. |>|    class Rectangle {...}
  36. |>|
  37. |>|    template<class SideT>
  38. |>|    class Square : public Rectangle<SideT, SideT> {...}
  39. |>|
  40. |>|In this case, Rectangle cannot inherit from Square; it would have to change
  41. |>|the types of the instance variables.  This is not an altogether artificial
  42. |>|example; I worked on a word processor (not written in an O.O. language) in
  43. |>|which horizontal and vertical distances were expressed in different units.
  44. |>|(This program had no use for squares, however.)
  45. |>
  46. |>If your intent is to use Squares on a system with different horizontal and
  47. |>vertical dimensions, then even your scheme of Const Inheritance doesn't solve
  48. |>the problem.  You still have to deal with how to specify a square.  Is it
  49. |>expressed in horizontal or vertical units?  Or both?  If you're going to
  50. |>constrain the problem so as to exclude alternate solutions, make sure your own
  51. |>solution still works.
  52. |
  53. |Sigh.  Do I have to explain every little detail?  If I were simply using
  54. |different dimensions for width and height, I wouldn't have bothered making a
  55. |template.
  56.  
  57. Duh!  You're the one who proposed this example, and of course I understand that
  58. the use of class variables implies multiple class instantiations with varying
  59. measure types.  You're also the one who insists that conventions are not enough
  60. to solve the problem of overspecification.  I still don't understand how your
  61. const inheritance proposal makes this example workable.  When you say:
  62.  
  63. |I would not be able to use Square in the first context [lines, chars], but it
  64. |would be quite usable in the other [points].
  65.  
  66. You seem to imply that you would allow the creation of template instantiations
  67. that would violate your strictures, or else somehow limit the set of classes
  68. that could be substituted in template variables.  Somehow I don't think this is
  69. what you have in mind, but you don't make it very clear what you mean, and you
  70. seem to be getting further away from your const inheritance proposal.  How does
  71. that all fit in to this?  By preventing all of it?
  72.  
  73. |Selective inheritance might be a useful feature to add to the language.  But
  74. |I see const inheritance as a completion of a feature already in the
  75. |language, not as an entirely new feature.
  76.  
  77. Const inheritance is a form of selective inheritance!  As such, it is a subset
  78. which provides one crude criterion for passing members down.  It's as much an
  79. entirely new feature as selective inheritance, and I'm arguing for the
  80. inclusion of neither.
  81. ________________________________________________________________________________
  82. Robert Reed            Home Animation Ltd.        503-656-8414
  83. robert@slipknot.rain.com    5686 First Court, West Linn, OR 97068
  84.  
  85. I have a 3 year old dog I named, "Stay."  It was great when he was a puppy. 
  86. I'd call him, "Come here, Stay, Come here, Stay."
  87. --Steve Wright
  88. ________________________________________________________________________________
  89.