eppstein@garfield (David Eppstein) (09/19/88)
I'm entering this discussion for a question raised about information hiding, and not so much for whether or not to befriend (although I agree with the side that says appropriate uses of friends are rare). In <86@cybaswan.UUCP>, eeartym@cybaswan.UUCP (Dr R.Artym eleceng ) writes: > The issue is protection. A plex stores elements of type T into a list > of chunks. Both plex and chunk are ``parameterized'' by type T (faked > with macro-expansion). Because of the limitations of macro-expansion > and of header files, they must be defined in the same .h file. > However, I don't want clients to access the chunks. Therefore I make > all the chunk operations private, and I give the plex access to them > by making it a friend. This is different from how I typically try to hide things. In particular, I care about whether the wrong parts of my programs can see my actual data, but I trust myself to reuse or not reuse code appropriately. So in this example I wouldn't care if the definitions of the chunks were public, so long as the chunks themselves were accessed by private members of the plex. This lets me use inline functions instead of friends. Of course it would be better if the chunk definitions didn't have to be in the include file, but my reason why it would be better is then the file would be less cluttered by information irrelevant to most users of it. -- David Eppstein eppstein@garfield.cs.columbia.edu Columbia U. Computer Science