comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de>
Subject: Re: newbie - OOP in Ada Set and Get Methods
Date: Tue, 28 Dec 2004 19:58:38 +0000 (UTC)
Date: 2004-12-28T19:58:38+00:00	[thread overview]
Message-ID: <cqsdte$9np$1@a1-hrz.uni-duisburg.de> (raw)
In-Reply-To: 1104255406.015130.138150@z14g2000cwz.googlegroups.com

R <ruthless@poczta.onet.pl> 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



  parent reply	other threads:[~2004-12-28 19:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-28 12:41 newbie - OOP in Ada Set and Get Methods R
2004-12-28 13:36 ` Jeff C r e e.m
2004-12-28 16:26   ` R
2004-12-28 17:01     ` Jeff C r e e.m
2004-12-28 17:30       ` R
2004-12-28 17:20     ` Martin Dowie
2004-12-28 17:36       ` R
2004-12-28 19:47         ` Mark Lorenzen
2004-12-28 19:48         ` Adrien Plisson
2004-12-28 19:58         ` Georg Bauhaus [this message]
2004-12-28 21:17         ` Martin Dowie
2004-12-29 10:06           ` R
2004-12-29 12:33             ` Martin Dowie
2004-12-29 17:35             ` Georg Bauhaus
2004-12-29 19:12             ` Martin Krischik
2004-12-30 12:14               ` Georg Bauhaus
2004-12-29 19:11         ` Martin Krischik
2004-12-28 13:39 ` Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox