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-Thread: 103376,ccb21d128bf5f2ae X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!t-online.de!news-lei1.dfn.de!news-ham1.dfn.de!news.uni-hamburg.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: newbie - OOP in Ada Set and Get Methods Date: Tue, 28 Dec 2004 19:58:38 +0000 (UTC) Organization: GMUGHDU Message-ID: References: <1104237673.373489.128290@z14g2000cwz.googlegroups.com> <1104251213.061878.187430@f14g2000cwb.googlegroups.com> <1104255406.015130.138150@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1104263918 9977 134.91.1.34 (28 Dec 2004 19:58:38 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Tue, 28 Dec 2004 19:58:38 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: g2news1.google.com comp.lang.ada:7272 Date: 2004-12-28T19:58:38+00:00 List-Id: R wrote: : because all OOP languages uses references to pass the objects as : parameters... Ada may or may not use references depending on what kind of value a subprogram parameter takes. But for tagged types, passing values is always by reference, no need for an explicit pointer. Object construction is slightly different in Ada, I think. The function approach is one way to do it. I liked this discussion: http://www.cmis.brighton.ac.uk/staff/je/adacraft/ch14.htm http://www.cmis.brighton.ac.uk/staff/je/adacraft/ch15.htm You can also use a constructor procedure. For example, package Test_Class is type Rec_1 is tagged record value: Integer; end record; procedure make(r: in out Rec_1; .......); -- initialises all components of `r` function get(r: Rec_1) return Integer; procedure set(r: in out Rec_1; v: Integer); end Test_Class; Then somewhere else in your program, declare x: Rec_1; begin make(x, .......); set(x, 5); get(x); end; You could also have automatic initialisation using default values for the object's components, type Rec_1 is tagged record value: Integer := default_value; end record; One more thing: Ada allows nesting blocks. So in many cases, you can combine these techniques (and more). Note that `default_value` can be a function. -- Georg