home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!tessi!eaglet!slipknot!robert
- From: robert@slipknot.rain.com (Robert Reed)
- Subject: Re: Const Inheritance
- Message-ID: <BxHBGD.DtA@slipknot.rain.com>
- Reply-To: robert@slipknot.rain.com.UUCP (Robert Reed)
- Organization: Home Animation Ltd.
- References: <1992Nov05.165658.34729@Cookie.secapl.com> <Bx9vsr.4ML@slipknot.rain.com> <1992Nov09.162957.31736@Cookie.secapl.com>
- Date: Tue, 10 Nov 1992 02:41:01 GMT
- Lines: 77
-
- In article <1992Nov09.162957.31736@Cookie.secapl.com> frank@Cookie.secapl.com (Frank Adams) writes:
- |>I see nothing in my counter-proposal which would deny the operation of this
- |>function.
- |
- |But I can do the following:
- |
- | Square s;
- | setDimensions(s, 2, 3);
- |
- |This does not work; after the call, the width will not be 2. (Of course,
- |presented this baldly, I would not expect it to work; but I could be passing
- |s to some other function which took a rectangle argument, and called
- |setDimensions on it; the resulting bug is quite subtle.)
-
- My point remains that we can design conventions to deal with overspecification
- problems like this under the auspices of the current language. Your
- alternative would be a bludgeon that would deny the access to ANY object
- modification functions.
-
- |>|There is another problem with this, if I decide to generalize a bit: I may
- |>|want to define:
- |>|
- |>| template<class WidthT, class HeightT>
- |>| class Rectangle {...}
- |>|
- |>| template<class SideT>
- |>| class Square : public Rectangle<SideT, SideT> {...}
- |>|
- |>|In this case, Rectangle cannot inherit from Square; it would have to change
- |>|the types of the instance variables. This is not an altogether artificial
- |>|example; I worked on a word processor (not written in an O.O. language) in
- |>|which horizontal and vertical distances were expressed in different units.
- |>|(This program had no use for squares, however.)
- |>
- |>If your intent is to use Squares on a system with different horizontal and
- |>vertical dimensions, then even your scheme of Const Inheritance doesn't solve
- |>the problem. You still have to deal with how to specify a square. Is it
- |>expressed in horizontal or vertical units? Or both? If you're going to
- |>constrain the problem so as to exclude alternate solutions, make sure your own
- |>solution still works.
- |
- |Sigh. Do I have to explain every little detail? If I were simply using
- |different dimensions for width and height, I wouldn't have bothered making a
- |template.
-
- Duh! You're the one who proposed this example, and of course I understand that
- the use of class variables implies multiple class instantiations with varying
- measure types. You're also the one who insists that conventions are not enough
- to solve the problem of overspecification. I still don't understand how your
- const inheritance proposal makes this example workable. When you say:
-
- |I would not be able to use Square in the first context [lines, chars], but it
- |would be quite usable in the other [points].
-
- You seem to imply that you would allow the creation of template instantiations
- that would violate your strictures, or else somehow limit the set of classes
- that could be substituted in template variables. Somehow I don't think this is
- what you have in mind, but you don't make it very clear what you mean, and you
- seem to be getting further away from your const inheritance proposal. How does
- that all fit in to this? By preventing all of it?
-
- |Selective inheritance might be a useful feature to add to the language. But
- |I see const inheritance as a completion of a feature already in the
- |language, not as an entirely new feature.
-
- Const inheritance is a form of selective inheritance! As such, it is a subset
- which provides one crude criterion for passing members down. It's as much an
- entirely new feature as selective inheritance, and I'm arguing for the
- inclusion of neither.
- ________________________________________________________________________________
- Robert Reed Home Animation Ltd. 503-656-8414
- robert@slipknot.rain.com 5686 First Court, West Linn, OR 97068
-
- I have a 3 year old dog I named, "Stay." It was great when he was a puppy.
- I'd call him, "Come here, Stay, Come here, Stay."
- --Steve Wright
- ________________________________________________________________________________
-