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.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-24 03:49:32 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!peernews-us.colt.net!newsfeed.news2me.com!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny03.gnilink.net.POSTED!53ab2750!not-for-mail From: "Stephane Richard" Newsgroups: comp.lang.ada References: <3F5F7FDC.30500@attbi.com> <3F6079A9.6080108@attbi.com> <3F60E380.4020307@attbi.com> <3F694186.5060709@crs4.it> <3F702545.6080704@crs4.it> Subject: Re: Is the Writing on the Wall for Ada? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: <0Fecb.247$kD3.123@nwrdny03.gnilink.net> Date: Wed, 24 Sep 2003 10:49:32 GMT NNTP-Posting-Host: 141.149.79.119 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny03.gnilink.net 1064400572 141.149.79.119 (Wed, 24 Sep 2003 06:49:32 EDT) NNTP-Posting-Date: Wed, 24 Sep 2003 06:49:32 EDT Xref: archiver1.google.com comp.lang.ada:42850 Date: 2003-09-24T10:49:32+00:00 List-Id: "Matthew Heaney" wrote in message news:ufzimx6mr.fsf@earthlink.net... > "Stephane Richard" writes: > > > I have a question about this idiom. > > > > Taking your example here I'd like to have a classic example of the following > > using that idiom: > > > > I have Bird class that can fly, chirp, eat, hear and build a nest. > > I have a Horse class that can eat, run, walk, hear and sleep > > > > 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 type A and B from type C. Perhaps the example I state here might > > make it clearer on how the idiom works? > > Here you go: > > package Birds is > > type Root_Bird_Type is > abstract tagged limited null record; > > type Bird_Class_Access is > access all Root_Bird_Type'Class; > > procedure Fly (Bird : access Root_Bird_Type) is abstract; > > procedure Eat (Bird : access Root_Bird_Type) is abstract; > > end Birds; > > > package Horses is > > type Root_Horse_Type is > abstract tagged limited null record; > > type Horse_Class_Access is > access all Root_Horse_Type'Class; > > procedure Eat (Horse : access Root_Horse_Type) is abstract; > > procedure Run (Horse : access Root_Horse_Type) is abstract; > > end Horses; > > > package Pegasus_Types is > > type Pegasus_Type is limited private; > > function Bird (Pegasus : access Pegasus_Type) > return Bird_Class_Access; > > function Horse (Pegasus : access Pegasus_Type) > return Horse_Class_Access; > > private > > type Bird_View (Pegasus : access Pegasus_Type) is > new Root_Bird_Type with null record; > > procedure Fly (Bird : access Bird_View); > procedure Eat (Bird : access Bird_View); > > type Horse_View (Pegasus : access Pegasus_Type) is > new Root_Horse_Type with null record; > > procedure Eat (Horse : access Horse_View); > procedure Run (Horse : access Horse_View); > > type Pegasus_Type is limited record > Bird : aliased Bird_View (Pegasus_Type'Access); > Horse : aliased Horse_View (Pegasus_Type'Access); > ... > end record; > > end Pegasus_Types; > > > Now I can say: > > declare > Pegasus : aliased Pegasus_Type; > begin > Fly (Bird (Pegasus'Access)); > Eat (Bird (Pegasus'Access)); > > Eat (Horse (Pegasus'Access)); > Run (Horse (Pegasus'Access)); > end; > > > There's no conflict between the Eat operation for Bird and the Eat > operation for Horse, because you can pick the view you need. > > Ahhh I see now, ok it's not quite what I thought it would be...(as per my aggregation assumption)..it makes sense now :-) -- St�phane Richard "Ada World" Webmaster http://www.adaworld.com