comp.lang.ada
 help / color / mirror / Atom feed
From: "Ekkehard Morgenstern" <ekkehard.morgenstern@onlinehome.de>
Subject: Re: Question about OO programming in Ada
Date: Wed, 26 Nov 2003 01:01:03 +0100
Date: 2003-11-26T01:01:03+01:00	[thread overview]
Message-ID: <bq0qfs$3ja$1@online.de> (raw)
In-Reply-To: uhe0sqfud.fsf@nasa.gov


"Stephen Leake" <Stephe.Leake@nasa.gov> schrieb im Newsbeitrag
news:uhe0sqfud.fsf@nasa.gov...
>
> > Do I have to use class-wide types for object-oriented programming, or
could
> > I use regular access types?
>
> Hmm. This very much depends on exactly what you mean by
> "object-oriented".

Ok. What I'd like to know is if I can view Ada record types as classes of
objects.

I.e. if I declare a record, like

        type My_Type1 is
        record
        Field1 : Integer;
        Field2:  Integer;
        end record;

Can I extend the record type like

        type My_Type2 is new My_Type with
        record
        Field3 : Integer;
        Field4 : Integer;
        end record;

such that the procedures declared to operate on type My_Type1 will operate
on the My_Type1 fields of My_Type2.

I gathered from what I read that I need to declare My_Type1 as a tagged
type.

Now, I read that method dispatching (with static dispatching corresponding
to method overloading in C++, and runtime dispatching corresponding to
virtual methods in C++), would be possible only by using a class-wide type,
such as My_Type1'Class in the first parameter of a procedure or in the
return value of a function.

First of all, how do I accomplish returning a reference in Ada? What is the
default behaviour of parameter passing and return in Ada? Someone said here
that if I use an "in" parameter in a procedure or function definition, the
object will be passed by reference. What about the returing of objects? Are
they returned by copy or returned by reference?

If I use a class-wide type, like My_Type1'Class, what kind of object is
that? Is it similar to Java's "object.class"?

What's the difference between passing a class-wide type as an in/out
parameter of a procedure, and passing an access to it?

i.e. the difference between

    procedure Proc( Param : in out Type'Class );

and

    type Type_Class_Access is access Type'Class;
    procedure Proc( Param : in Type_Class_Access );


> If you mean getting run-time dynamic dispatching, then somewhere in
> your system you need a class-wide type (not everywhere). You also need
> derived types with primitive operations. If these terms don't make
> sense, please read an Ada book, such as "Ada as a Second Language" by
> Norm Cohen; that will teach you what you need to know much more
> quickly than asking here.

I ordered myself a book about Ada already, "Programming in Ada 95" by John
Barnes, but it'll take a week or so till it arrives, so I'll have to make do
with other resources until then.

I think I know what run-time dynamic dispatching, class-wide types and
derived types refer to, but I'm not sure about implicit type conversions
that I can use.

For example, how do I get an access to an object in an expression?

Like, I have

    A : B ;
    C : access B;

how do I assign A to C? How can I get an access in mid-expression? Or is the
strong typing coming into effect that prevents assignment from one thing to
another?

Like, I'd want to do something similar like this:

    C := access A;

In C++, I can just write " C = &A" (if C is a pointer to B). How do I do
that in Ada?

I tried to use the pointer-like semantics of access to class-wide types, but
I ended up with doing manual type conversions (or casting) all over. Is that
normal?


> Or, try to explain here what you mean by "object-oriented". Use either
> C++ or Ada terms, but try to be very explicit. Then we can tell you
> how to do that correctly in Ada.

With object-oriented, I mean programming with classes of objects. Is that
explicit enough?

I would like to know how to handle methods of classes properly.

In the "Ada 95: Guide for C/C++ Programmers", the author used only access to
class-wide types, and some people here say that you don't really need them,
and I'd like to know why and how I could use the more implicit semantics of
parameter passing to get the same effect.

I thought by using this newsgroup, I could be spared from reading in the Ada
95 Rationale. Which is very explicit, but also verbose, and I'd like to make
my learning process quicker. ;-)

Also, some things aren't explained properly in the Rationale, because it
assumes the reader is familiar with Ada.

Like, I would like to know more about parameter passing, but I haven't yet
found the place where to look in the Rationale.  (ok I'm a bit too lazy
right now ;-) -- English is a foreign language to me, and I'd rather not
read umpteen pages of Ada language theory when I can avoid it! ;-) )


> You have several very basic misunderstandings; reading a good Ada book
> would probably be a good idea.

Might be that I have several misunderstandings.

I will read the Ada book when I receive it! :-)






  reply	other threads:[~2003-11-26  0:01 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
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 [this message]
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