CompuServe Messages

ObjectOriented

    21-Sep-95 09:23:43
Sb: #48223-ObjectOriented
Fm: Greg Comeau@Comeau Cmptg 72331,3421
To: Peter Wade 100265,2740
>When you put it that way, yes it does make sense. I suppose its a case of >terminology, I consider local variables and statics as a way of avoiding >confusion But, indeed, that's part of it here too. I suspect you unfamiliarity is throwing you a curve somehow. >(I have a personal rule that certain variable names like i and j are >NEVER global). I even prefer to avoid them as locals, but surely yes, they'd never be globals with this names. Anyway, it isn't the name itself that provides the encasulation, its things like its place'age (for instance, scope). As previously mentioned, in C, we had minimal support: .c/.h, static, local variables (whethere static or not), and function prototypes (borrowed directly from C++ BTW!). We also have: functions, structure members, (barely) typedef, { … }'s, pointers. Certainly you cannot go stomp on a local variable (even a static) in a function, by name, from outside that function w/o having made its address known somehow. That definitely involves abstraction (usually not thought this way, but a function definitely involves facets of abstration) and encapsulation (black boxing providing a public interface, and what happens "inside" is "of no concern" (philosophically that is, of course in the real world, it can be of concern, for instance, it might be too slow). Anyway, C++ really only add a few things to this: public/protected/private, C++ namespace's ("recent addition"), and static members. But oddly, these "trivial" additions takes C's bare support to something quite useful. >> You may even also want to consider that the enforcement is not that at >> all but indeed categories of usage for the various parts of your code. >> It definitely makes a lot of sense. > >Thinking about it more, I suppose you could use it as a more flexible way of >keeping things seperate, like using statics without having to put everything in >seperate files. Absolutely. Private doesn't just mean "outsiders cannot touch me" but "for the class use only". That may sound the same but its the seperation that's important here too. >Obviously I have a lot to learn… We all do. It takes a lifetime. Don't feel disappointed 🙂