From: "Ekkehard Morgenstern" <ekkehard.morgenstern@onlinehome.de>
Subject: Re: Question about OO programming in Ada
Date: Wed, 26 Nov 2003 01:22:06 +0100
Date: 2003-11-26T01:22:06+01:00 [thread overview]
Message-ID: <bq0rna$ooh$1@online.de> (raw)
In-Reply-To: 21836716.smDW2dK3SM@linux1.krischik.com
"Martin Krischik" <krischik@users.sourceforge.net> schrieb im Newsbeitrag
news:21836716.smDW2dK3SM@linux1.krischik.com...
> Ekkehard Morgenstern wrote:
> > Do I have to use class-wide types for object-oriented programming, or
> > could I use regular access types?
> >
> > Like, when I declare a procedure
> >
> > procedure A ( B: in access all T'Class )
>
> I made this mistake as well when I started. For OO it should be only:
>
> procedure A ( B: in out T )
>
> Unlike C++ no access is needed in Ada. And a class wide Types make your
> procedure non "virtual". Some Tutorials are quite bad about describing
that
> point.
Are you sure?
Should it not read at least
procedure A ( B: in out T'Class )
Because when I inherit from a class I would like the methods of the base
class to work on the derived class as well.
Both the Ada Rationale and the Guide for C/C++ programmers say that you have
to declare the first parameter of a procedure or the return value of a
function to be of the class-wide type of the class to get the dynamic
runtime dispatching behaviour from Ada (like virtual functions in C++).
How would I have to declare them?
And how do I cast an object back to the reduced record type? And is that
necessary at all?
I guess I'll have to write some simple test cases.
> > procedure A ( B: in access all T )
>
> Should be:
>
> procedure A ( B: access T )
>
> and is Ok.
The Ada 95 Reference says that the "all" attribute provides read-write
access to the object, while omitting it would only provide read-only access?
Or did I get that wrong?
(btw, I made short cuts with my examples, I know not all of the notation I
gave can be actually compiled)
> > procedure A ( B: in out T )
>
> Much better then using an acces type.
But how about inheritance? Will the procedure operate on a type derived from
T?
> > procedure A ( B: in T )
>
> Is like using "const&" in C++.
How about function returns? Can I return a reference to an object in the
same way?
> In Ada access type are not as often needed as in C++. So don't use then
> unless you need them. References are done automatily by Ada.
>
> If you know C++ then you will know about:
>
> virtual void A (T& B); or virtual void A (T B);
>
> As I said Ada will make the '&' Reference automaticly.
Does that help to avoid casting as well? And how do I return a reference
from a function? Or should I use procedures with in out parameters instead?
> The "all" part is needed access to an object which have not been created
> with "new".
You mean it doesn't give access to an object that was elaborated normally?
Now that explains some things.
> Using "all" for an access might reduce performace since the
> compiler might have to do some extra checking on the access. Avoid if not
> needed.
Ok.
> > I would like to program as cleanly as possible in Ada right from the
> > start, so I'd be glad if someone could give me some hints. :-)
>
> Hope I was of help.
Yes, thank you. :-)
> You might also browse my Web page http://adacl.sourceforge.net. There are
> lots of sources you can browse right on the web without downloading them.
Thanks, I have taken a look at it (not finished looking yet! ;-) ).
next prev parent reply other threads:[~2003-11-26 0:22 UTC|newest]
Thread overview: 109+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-25 19:04 Question about OO programming in Ada Ekkehard Morgenstern
2003-11-25 20:17 ` Randy Brukardt
2003-11-26 0:34 ` Ekkehard Morgenstern
2003-11-26 6:17 ` Vinzent 'Gadget' Hoefler
2003-11-26 9:29 ` Dmitry A. Kazakov
2003-11-26 15:54 ` Stephen Leake
2003-11-26 20:07 ` Randy Brukardt
2003-11-26 21:36 ` Stephen Leake
2003-11-26 8:56 ` Peter Hermann
2003-11-25 20:55 ` Martin Krischik
2003-11-26 0:22 ` Ekkehard Morgenstern [this message]
2003-11-26 1:00 ` Jeffrey Carter
2003-11-26 16:36 ` Martin Krischik
2003-11-26 18:09 ` Robert I. Eachus
2003-11-27 13:45 ` Jean-Pierre Rosen
2003-11-25 21:48 ` Stephen Leake
2003-11-26 0:01 ` Ekkehard Morgenstern
2003-11-26 1:16 ` Jeffrey Carter
2003-11-26 15:10 ` Georg Bauhaus
2003-11-26 15:48 ` Stephen Leake
2003-11-26 16:24 ` Hyman Rosen
2003-11-26 17:58 ` Robert I. Eachus
2003-11-27 2:10 ` Ekkehard Morgenstern
2003-11-27 10:15 ` Ludovic Brenta
2003-11-27 18:35 ` Jeffrey Carter
2003-11-28 4:35 ` Hyman Rosen
2003-11-28 7:28 ` Vinzent 'Gadget' Hoefler
2003-11-28 8:46 ` Dale Stanbrough
2003-11-28 10:16 ` Vinzent 'Gadget' Hoefler
2003-12-01 15:57 ` Martin Krischik
2003-12-01 16:47 ` Hyman Rosen
2003-12-03 18:35 ` Martin Krischik
2003-12-01 21:13 ` Jeffrey Carter
2003-12-02 8:47 ` Dmitry A. Kazakov
2003-12-03 9:29 ` Pascal Obry
2003-12-03 11:26 ` Dmitry A. Kazakov
2003-12-03 12:49 ` Ludovic Brenta
2003-12-03 13:41 ` Dmitry A. Kazakov
2003-12-03 14:11 ` Ludovic Brenta
2003-12-03 14:45 ` Dmitry A. Kazakov
2003-12-03 15:44 ` Hyman Rosen
2003-12-03 16:11 ` Dmitry A. Kazakov
2003-12-03 18:20 ` David C. Hoos
[not found] ` <28eb01c3b9ca$25b18870$b101a8c0@sy.com>
2003-12-03 18:35 ` Hyman Rosen
2003-12-03 20:05 ` Randy Brukardt
2003-12-03 20:57 ` Hyman Rosen
2003-12-03 21:16 ` Hyman Rosen
2003-12-03 22:04 ` Pascal Obry
2003-12-03 22:34 ` Hyman Rosen
2003-12-04 1:23 ` Robert I. Eachus
2003-12-04 7:15 ` Hyman Rosen
2003-12-04 17:43 ` Warren W. Gay VE3WWG
2003-12-04 8:55 ` Dmitry A. Kazakov
2003-12-04 19:13 ` Randy Brukardt
2003-12-04 19:29 ` Hyman Rosen
2003-12-04 21:32 ` Robert I. Eachus
2003-12-05 8:43 ` Dmitry A. Kazakov
2003-11-27 22:12 ` Robert I. Eachus
2003-11-28 6:37 ` Simon Wright
2003-11-30 2:51 ` Robert I. Eachus
2003-12-06 7:48 ` Chad Bremmon
2003-12-06 13:33 ` Jeff C,
2003-12-06 22:44 ` Hyman Rosen
2003-12-07 3:02 ` Chad Bremmon
2003-12-07 7:53 ` Hyman Rosen
2003-12-07 15:34 ` James Rogers
2003-12-07 18:30 ` Martin Krischik
2003-12-07 20:25 ` James Rogers
2003-12-08 3:36 ` Hyman Rosen
2003-12-08 4:42 ` Chad Bremmon
2003-12-08 8:42 ` Hyman Rosen
2003-12-08 9:34 ` Dmitry A. Kazakov
2003-12-08 13:25 ` Hyman Rosen
2003-12-08 15:05 ` Dmitry A. Kazakov
2003-12-09 4:38 ` Hyman Rosen
2003-12-09 8:19 ` Dmitry A. Kazakov
2003-12-09 13:29 ` Hyman Rosen
2003-12-09 14:36 ` Dmitry A. Kazakov
2003-12-09 15:05 ` Hyman Rosen
2003-12-09 15:59 ` Dmitry A. Kazakov
2003-12-09 16:41 ` Hyman Rosen
2003-12-10 11:32 ` Dmitry A. Kazakov
2003-12-10 15:27 ` Hyman Rosen
2003-12-10 17:15 ` Dmitry A. Kazakov
2003-12-08 17:55 ` Chad Bremmon
2003-12-08 23:09 ` Hyman Rosen
2003-12-09 8:26 ` Dmitry A. Kazakov
2003-12-08 19:33 ` Martin Krischik
2003-12-09 4:41 ` Hyman Rosen
2003-12-08 17:27 ` Chad Bremmon
2003-12-08 18:44 ` Georg Bauhaus
2003-12-08 19:27 ` Martin Krischik
2003-12-08 19:36 ` Chad Bremmon
2003-12-09 4:43 ` Hyman Rosen
2003-12-08 23:23 ` Hyman Rosen
2003-12-08 19:25 ` Martin Krischik
2003-12-07 21:29 ` Peter C. Chapin
2003-12-08 3:44 ` Hyman Rosen
2003-12-08 3:46 ` Hyman Rosen
2003-12-08 5:54 ` James Rogers
2003-12-08 8:45 ` Hyman Rosen
2003-12-07 17:39 ` Chad Bremmon
2003-12-08 23:39 ` Hyman Rosen
2003-12-09 2:36 ` Chad Bremmon
2003-12-09 4:52 ` Hyman Rosen
2003-12-09 11:24 ` Georg Bauhaus
2003-12-09 18:42 ` Chad Bremmon
2003-12-09 20:11 ` Hyman Rosen
2003-12-08 23:40 ` Hyman Rosen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox