Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!amdcad!ames!mailrus!purdue!decwrl!labrea!polya!shap From: shap@polya.Stanford.EDU (Jonathan S. Shapiro) Newsgroups: comp.lang.c++ Subject: Re: Can we hide the private part of a class ? Message-ID: <4193@polya.Stanford.EDU> Date: 30 Sep 88 18:47:18 GMT References: <1358@stratus> <1988Sep29.044111.16104@utzoo.uucp> Reply-To: shap@polya.Stanford.EDU (Jonathan S. Shapiro) Organization: Stanford University Lines: 43 In article <1988Sep29.044111.16104@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: >In article <1358@stratus> hsu@stratus (Yung-Kao Hsu) writes: >>This features make package/module interfaces cleaner (you don't see any >>implementation information at all), and there are more advantages. >>But, I couldn't find anything similiar in C++ !! > >The user can't access x, so seeing it won't do him much good. However, >the compiler now knows exactly how big a variable of class X is, so it >can generate code that knows this. If those private declarations were >hidden somewhere else, either the compiler has to get much more complex >or else class variables can't be as efficient as ordinary variables. >For example, as I recall (it's been a while...), since Modula 2 doesn't >tell the compiler how big the variable is, all the compiler can do for >space allocation is to allocate a pointer to the variable, and do all >accesses via that pointer. All of what you say is true and good, and I think the tradeoff is worth it, but it is worth pointing out on the other side that a consequence of unifying the private and public parts of the code are an increase in the header dependencies that can get explosive. Consider having a private member of type froboz. Even if there is no public member of type froboz, all of the includers of the class definition have to know what a froboz is - EVEN though they can't make any use of the relevant member. As someone who has developed large C++ systems, I have had occasion to sadly regret this fact. On the other hand, I am more concerned with the fact that there is NO way out of the run time cost in modula. One technique that I have seen used to avoid this is to make all of the private members part of a structure and declare the private part as a structure reference. This is cumbersome to the coder, but in a big system can be worth it. Then when you have completed development you make it an immediate object and insert a #include in the class def header file. The flip side of this is that what you say about both languages is wrong given a good librarian. The librarian could maintain the component sizes, and at least for the client functions that would eliminate unneeded dependency in both languages, subject to the constraint that the private part be compiled first. Jon