From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8b8748382fcfacc1 X-Google-Attributes: gid103376,public From: "John J. Rusnak" Subject: Re: friend classes in ada95 Date: 2000/04/14 Message-ID: <38F7BC00.F88AD37E@mindspring.com>#1/1 X-Deja-AN: 611347104 Content-Transfer-Encoding: 7bit References: <38F6B617.34E216A7@emw.ericsson.se> X-Accept-Language: en X-Server-Date: 15 Apr 2000 00:52:42 GMT Content-Type: text/plain; charset=us-ascii Organization: MindSpring Enterprises Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-04-15T00:52:42+00:00 List-Id: Stefan Folkesson wrote: > In ADA95, is there a way to make the private part of one class > accessable from another (see friend classes in C++)? > > The reason I wonder this is because I want to apply the 'Iterator > Pattern' in my design. This demands that the Iterator object can access > the attributes of the Aggregate object. > > Is this possible? Is there a pragma to supress the access check or do I > have to declare the attributes of the Aggregate class in the public part > of the specification. > > /Stefan Yes, and no pragma is needed. In fact, a class has no control (that I am aware of) of who its "friends" are. The way to implement a friend relationship is to use a child package. A child package automatically has visibility into the private parts of its parent's spec. The implementation of a friend class through a child package does involve a tighter coupling of the class and its "friend", but this is a good thing. One should only implement a friend relationship if there is a strong need (and a need for strong coupling between the classes). -John