Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!daver!dlb!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c++ Subject: Re: Public vs Private header files in C++ Message-ID: <18759@prometheus.megatest.UUCP> Date: 3 Jun 91 23:56:42 GMT References: <5243@servax0.essex.ac.uk> Organization: Megatest Corporation, San Jose, Ca Lines: 37 From article <5243@servax0.essex.ac.uk>, by whisd@sersun1.essex.ac.uk (Whiteside S D B): > I wonder if anyone has any suggestions on this: > > Modula-2, for example, provides a separate "public" interface to the user's > of a module. [... but not C++, which means ... ] > i) security might be compromised: it's possible for the user to "hack" into > the data structures Don't worry about it. You can't save the world from incompetent hackers. Besides, there may come a day when you need to hack into a private data structure as a stop-gap measure while you wait for a vendor or coworker to fix a buggy library class. > ii) when implementation-specific features are changed (such as, in a recent > case with me, where I wanted a different sized array in my class) which > do not change the semantics of the class, the user has to be recompiled as > it has access to the same information as the class itself. The compiler (or a "smart" linker) *uses* that info to size the structure. If that's not what is wanted, the implementer should write the class so that the array is sized and created by the class's methods, particularly constructors. You can have it either way, you just have to know with way you want it. > iii) The user is burdened with too much detail when using the header file > as a documentation aid. Perhaps, but we can live with that. I would usually prefer too much info to too little. If (heaven forbid!) there is a bug in the implementation of the class, access to the private declarations of the class may be the ticket to figuring out what is wrong. > Can these be overcome with existing C++ constructs? I don't think you've named any problems that really need to be "overcome", but you can do the things you want using plain old C++.