Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!att!cbnewsl!strange From: strange@cbnewsl.ATT.COM (philip.e.brown) Newsgroups: comp.lang.c++ Subject: Re: information hiding Message-ID: <960@cbnewsl.ATT.COM> Date: 30 Jun 89 13:59:34 GMT References: <7709@spool.cs.wisc.edu> <14.UUL1.3#5109@pantor.UUCP> Reply-To: strange@cbnewsl.ATT.COM (philip.e.brown) Organization: AT&T Bell Laboratories Lines: 73 There is still some discussion about this, so I'll pass along the mail I sent to the original poster. (Subsequent articles have covered some of this already.) /////////////////////////////////////////////////////// In article <6031@watdcsu.waterloo.edu> you write: > >I am a little curious as to how one can completely remove implementation >details of a C++ class from the user of the class. >I would like to design a system that users need only know the public >declarations and nothing else to use the class. >It seems to me that I will always have to provide a Header file that >contains at least the declarations of all my private information. >Ultimately, I would like to give them a library containing my classes and >NOTHING else. >Could someone please clue me in! As with everything else, there is a cost for complete information hiding. The cost here is the added level of indirection necessary to defer implementation details. My suggestion is to try something like: ////////////// // header file class hide1; // classes for hidden implementation ... class hideN; class interface { hide1 *hidden1; // handle into implementation ... hideN *hiddenN; public: interface_func1(); // can't define yet ... interface_funcM(); }; // end header file ////////////////// ////////////// // source file class hide1 { /* implementation details */ }; ... class hideN { /* implementation details */ }; interface::interface_func1() { /* implementation details */ } ... interface::interface_funcM() { /* implementation details */ } // end source file ////////////////// The header file contains only the information necessary for the interface. All else is hidden. An additional benefit is that recompilation is only necessary when the interface has changed. When just the implementation has been updated, only the files containing the implementation are affected. Phil Brown AT&T Bell Labs attunix!strange