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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-23 20:03:44 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!elnk-nf2-pas!elnk-pas-nf1!newsfeed.earthlink.net!west.cox.net!east.cox.net!peer01.cox.net!cox.net!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny01.gnilink.net.POSTED!53ab2750!not-for-mail From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5b) Gecko/20030901 Thunderbird/0.2 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Is the Writing on the Wall for Ada? References: <3F5F7FDC.30500@attbi.com> <3F6079A9.6080108@attbi.com> <3F60E380.4020307@attbi.com> <3F694186.5060709@crs4.it> <3F702545.6080704@crs4.it> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Wed, 24 Sep 2003 03:03:42 GMT NNTP-Posting-Host: 162.83.244.79 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny01.gnilink.net 1064372622 162.83.244.79 (Tue, 23 Sep 2003 23:03:42 EDT) NNTP-Posting-Date: Tue, 23 Sep 2003 23:03:42 EDT Xref: archiver1.google.com comp.lang.ada:42841 Date: 2003-09-24T03:03:42+00:00 List-Id: Stephane Richard wrote: > How, using your idiom, would I go about creating a Pegasus class ? > > From reading your example it seems to me you're create an aggregation of > TypeA and B from type C. Perhaps the example I state here might make it > clearer on how the idiom works>? It's really very simple. The A and B types are each augmented with a pointer which points back to the aggregate object which contains them. Then methods can use that back pointer to access the containing object, and then its components, no matter what they are. The "magic" is that Ada initializaes this back pointer automatically when it's declared properly, as in the C_type / (C_Type'Access) code in the previous message. For the "Pegasus" class, the 'eat' and 'hear' functions of the Bird and Horse parts can simply call a common method of the overall class. I'll rewrite Matthew's example in C++, just for fun: struct A_Type { virtual void A_Op() = 0; int X; }; struct B_Type { virtual void B_Op() = 0; int Y; }; struct C_Type; struct A_View : A_Type { C_Type *C; A_View(C_Type *c) : C(c) { } void A_Op(); }; struct B_View : B_Type { C_Type *C; B_View(C_Type *c) : C(c) { } void B_Op(); }; struct C_Type { A_View A; B_View B; int Z; C_Type() : A(this), B(this) { } // Ada does this by itself }; void A_View::A_Op() { int &X = this->X; int &Y = C->B.Y; int &Z = C->Z; } void B_View::B_Op() { int &X = C->A.X; int &Y = this->Y; int &Z = C->Z; }