comp.lang.ada
 help / color / mirror / Atom feed
From: "Christian Jaensch, FRG" <chris@IFR.LUFTFAHRT.UNI-STUTTGART.DE>
Subject: Re: on OO differnces between Ada95 and C++
Date: 1996/02/21
Date: 1996-02-21T00:00:00+00:00	[thread overview]
Message-ID: <9602211120.AA09651@ifr1.Luftfahrt.Uni-Stuttgart.DE> (raw)

Nasser Abbasi <nabbasi@QUALCOMM.COM> 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
-----------------------------------------------------------------------------




             reply	other threads:[~1996-02-21  0:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-02-21  0:00 Christian Jaensch, FRG [this message]
  -- strict thread matches above, loose matches on Subject: below --
1996-02-26  0:00 on OO differnces between Ada95 and C++ Simon Johnston
1996-02-20  0:00 Nasser Abbasi
1996-02-20  0:00 ` Robert I. Eachus
1996-02-20  0:00 ` Norman H. Cohen
1996-02-21  0:00   ` Mark A Biggar
1996-02-22  0:00     ` Norman H. Cohen
1996-02-27  0:00   ` Adam Morris
1996-02-20  0:00 ` Jerome Desquilbet
1996-02-21  0:00   ` Robert Dewar
1996-02-22  0:00     ` Jerome Desquilbet
1996-02-24  0:00       ` Robert Dewar
1996-02-22  0:00   ` Pete Becker
1996-02-23  0:00     ` Jerome Desquilbet
1996-02-26  0:00     ` Darren C Davenport
1996-02-26  0:00       ` Pete Becker
1996-02-27  0:00         ` Nigel Perry
1996-02-21  0:00 ` Darren C Davenport
1996-02-21  0:00 ` Jon S Anthony
1996-02-21  0:00 ` John English
1996-02-22  0:00   ` Gene Ouye
1996-02-26  0:00     ` John English
1996-02-22  0:00   ` Nasser Abbasi
1996-02-26  0:00     ` John English
1996-02-27  0:00       ` Dale Stanbrough
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox