Newsgroups: comp.std.c++ Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!world!wmm From: wmm@world.std.com (William M Miller) Subject: Re: protected != public-to-derived Message-ID: <1991Mar25.210620.13970@world.std.com> Organization: The World Public Access UNIX, Brookline, MA References: <1991Mar24.010442.27298@kestrel.edu> <1991Mar24.205156.10206@world.std.com> <1991Mar25.183627.6041@kestrel.edu> Date: Mon, 25 Mar 1991 21:06:20 GMT Lines: 31 gyro@kestrel.edu (Scott Layson) writes: > Put another way, why do you want to make `balance' a member variable > of `Account' if you *don't* want the derived classes of `Account' to > be able to access each other's balance? I'd put "balance" into the base class as a simple matter of factoring: every Account will have one, so it's most convenient to put it once and for all into the base class instead of having to declare it over and over again in each derived class. If I had a situation in which derived classes needed to be able to manipulate each other's data, I'd probably make them mutual friends; I don't think it would have occurred to me to put the data into the protected section of the base class. > b) it goes against the grain of "the unit of protection > is the class, not the object" (I'm not saying it literally contradicts > that philosophy, only that it seems to) I'm afraid I don't see the relationship here. You're not restricted to "this" -- *any* pointer to, reference to, or object of the correct class or any class derived therefrom is permissible; the restriction only applies to pointers or references to or objects of a base or sibling class. > Since there's another way to achieve the protection you want... This sounds like the argument over passive restraints versus seatbelts. It's nice to have that airbag in the steering column in case I forget to buckle up or in case I decide that it's only a short, safe trip -- but it's not free. -- William M. Miller, Glockenspiel, Ltd. wmm@world.std.com