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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56131a5c3acc678e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-25 16:01:01 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.stueberl.de!npeer.de.kpn-eurorings.net!rz.uni-karlsruhe.de!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: "Ekkehard Morgenstern" Newsgroups: comp.lang.ada Subject: Re: Question about OO programming in Ada Date: Wed, 26 Nov 2003 01:01:03 +0100 Organization: 1&1 Internet AG Message-ID: References: NNTP-Posting-Host: p508c004b.dip0.t-ipconnect.de X-Trace: online.de 1069804860 3690 80.140.0.75 (26 Nov 2003 00:01:00 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Wed, 26 Nov 2003 00:01:00 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Xref: archiver1.google.com comp.lang.ada:2944 Date: 2003-11-26T01:01:03+01:00 List-Id: "Stephen Leake" 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! :-)