Re: Question about OO programming in Ada
From: Ekkehard Morgenstern (ekkehard.morgenstern_at_onlinehome.de)
Date: 11/26/03
- Next message: Ekkehard Morgenstern: "Re: Question about OO programming in Ada"
- Previous message: Ekkehard Morgenstern: "Re: Question about OO programming in Ada"
- In reply to: Martin Krischik: "Re: Question about OO programming in Ada"
- Next in thread: Jeffrey Carter: "Re: Question about OO programming in Ada"
- Reply: Jeffrey Carter: "Re: Question about OO programming in Ada"
- Reply: Martin Krischik: "Re: Question about OO programming in Ada"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 26 Nov 2003 01:22:06 +0100
"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 message: Ekkehard Morgenstern: "Re: Question about OO programming in Ada"
- Previous message: Ekkehard Morgenstern: "Re: Question about OO programming in Ada"
- In reply to: Martin Krischik: "Re: Question about OO programming in Ada"
- Next in thread: Jeffrey Carter: "Re: Question about OO programming in Ada"
- Reply: Jeffrey Carter: "Re: Question about OO programming in Ada"
- Reply: Martin Krischik: "Re: Question about OO programming in Ada"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|