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,9ac62ca34a465706 X-Google-Attributes: gid103376,public From: "Christian Jaensch, FRG" Subject: Re: on OO differnces between Ada95 and C++ Date: 1996/02/21 Message-ID: <9602211120.AA09651@ifr1.Luftfahrt.Uni-Stuttgart.DE>#1/1 X-Deja-AN: 140386457 sender: Ada programming language comments: cc: nabbasi@QUALCOMM.COM newsgroups: comp.lang.ada Date: 1996-02-21T00:00:00+00:00 List-Id: Nasser Abbasi wrote: > Hello, > > I have a simple comment, but probably a long way of > showing it :) > > I have been playing around with the OO features in Ada95 and > comparing it with C++. I noticed this little difference, and I'd > like to see what you think of it. [rest snipped...] Below, I slightly modified your example using the parent-child approach. This gets rid of the aspect that seemed that have bothered you (explicit with of package Account needed in main) in your approach. BTW, whenever things are closely related or types are extended as in your example, I preferably use the hierarchical package approach. It provides -- if done well -- amongst other benefits a fairly transparent view of the class hierarchy. Besides, the parent-child approach is needed if you make all your to be extended types private ;-). ------------------ account.ads --------------------------- package Account is type Money_Type is new integer range 1..100; -- just as an example type Account_Type is tagged record Balance : Money_Type; Account_Id : Integer; end record; end Account; ----------------- account-saving_account.ads ------------ Package Account.Saving_Account is type Saving_Account_Type is new Account_Type with record Interest : Money_Type; end record; -- ... end Account.Saving_Account; --------------- main.adb --------------------------- with Account.Saving_Account; -- provides implicit with clause of parent with Ada.Text_IO; use Ada.Text_IO; procedure Main is package Money_IO is new Ada.Text_IO.Integer_IO(Account.Money_Type); The_Saving_Account : Account.Saving_Account.Saving_Account_Type; The_Balance : Account.Money_Type; begin Money_IO.Get(The_Balance); The_Saving_Account.Balance := The_Balance; end Main; I hope this helps, -- _/_/_/_/ _/_/_/_/ _/_/_/_/ Christian Jaensch TEL: +49(0)881-64947 _/ _/ _/ _/ Narbonner Ring 14 FAX: +49(0)881-637444 _/ _/_/_/ _/ 82362 Weilheim _/ _/ _/ _/ FRG _/_/_/_/ _/_/_/_/ _/_/_/ C O N S U L T I N G em: chris@ifr.luftfahrt.uni-stuttgart.de -----------------------------------------------------------------------------