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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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 12:58:14 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Question about OO programming in Ada Date: Tue, 25 Nov 2003 21:55:25 +0100 Organization: AdaCL Message-ID: <21836716.smDW2dK3SM@linux1.krischik.com> References: Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1069793752 07 11691 XDn+VhL6p9zOrr1 031125 20:55:52 X-Complaints-To: usenet-abuse@t-online.de X-ID: S3Fyj0ZBretsBOkwizQGwo4dFPV7U6jlgAsHgU4lIzCbksKK6vZmkB User-Agent: KNode/0.7.2 Xref: archiver1.google.com comp.lang.ada:2941 Date: 2003-11-25T21:55:25+01:00 List-Id: Ekkehard Morgenstern wrote: > > Hi guys, > > I have a question about object-oriented programming in Ada: > > 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. > could I use a different method and still get all the benefits of Ada > object-oriented programming? > > Like, what about: > > procedure A ( B: in access all T ) Should be: procedure A ( B: access T ) and is Ok. > or > > procedure A ( B: in out T ) Much better then using an acces type. > or > > procedure A ( B: in T ) Is like using "const&" in C++. > Also, if I use access types, should I create new types or declare them > directly in the procedure/function, and what about the 'all' access > qualifier, should I create two types of access types (one with 'access' > and one with 'access all'), or should I declare them directly in the > procedure and decide individually what kind of access I need? 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. The "all" part is needed access to an object which have not been created with "new". 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. > 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. 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. With Regards. -- mailto://krischik@users.sourceforge.net http://adacl.sourceforge.net