Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!snorkelwacker!bloom-beacon!eru!luth!sunic!tut!tukki!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.lang.c++ Subject: Re: are 'friend's really necessary ?? Message-ID: <3837@tukki.jyu.fi> Date: 20 Mar 90 06:32:22 GMT References: <169@pollux.kulcs.uucp> <10589@alice.UUCP> <1082@targon.UUCP> Reply-To: sakkinen@jytko.jyu.fi (Markku Sakkinen) Organization: University of Jyvaskyla, Finland Lines: 38 In article <1082@targon.UUCP> ruud@targon.UUCP (Ruud Harmsen) writes: >In article <10589@alice.UUCP> ark@alice.UUCP (Andrew Koenig) writes: >>In article <169@pollux.kulcs.uucp>, herman@kulcs.uucp (Herman Moons) writes: >> >>> I don't know whether this question appeared earlier on the net. >>> Are there any *good* reasons for having the friend concept in C++ ? >> >>Sure. One of the most common is when you're writing several >>interrelated classes. >> > >Only too true. And isn't this also the fundamental weakness of the object >oriented concept? For in the real world, and so in any realistic >information system describing a part of that real world, *nearly all* >classes are interrelated to *nearly all* other classes. [...] > ... Here seems to be some misunderstanding - Koenig should probably have written "_tightly_ interrelating". A given class need generally be _directly_ interrelated only to relatively few other classes, which we could call its acquaintances. In most cases, the communication between acquaintances needs to use only public operations (and data). Sometimes however, there is a real need for a closer cooperation between some classes (without any inheritance relationship between them). That's what friend declarations are good for. Ada and Modula-2 have the advantage over almost all OO languages that really tightly interrelated types can be defined within the same package or module. Certainly both this facility and the friend concept of C++ can be easily misused also. Markku Sakkinen Department of Computer Science University of Jyvaskyla (a's with umlauts) Seminaarinkatu 15 SF-40100 Jyvaskyla (umlauts again) Finland SAKKINEN@FINJYU.bitnet (alternative network address)