comp.lang.ada
 help / color / mirror / Atom feed
From: Marin David Condic <nobody@noplace.com>
Subject: Re: Problems with tagged records and inheritance
Date: Fri, 11 Jul 2003 07:56:07 -0400
Date: 2003-07-11T11:56:13+00:00	[thread overview]
Message-ID: <3F0EA5D7.9020207@noplace.com> (raw)
In-Reply-To: m37k6qhv6n.fsf@insalien.org

That looks like a really helpful answer for an Ada newbie. It 
illustrates how to fix the problem very well. Just in case the OP had 
reasons to want visibility of AAA, we should point out that the way to 
create a child package looks something like this:

package Base_Class is
...
type Base is tagged private;
...
type Base is tagged record
          AAA: Integer:=1;
       end record;

end Base_Class ;

...

package Base_Class.Child_Class is

type Child is new Base with private;
....
type Child is new Base with record
         BBB: Integer:=5;
       end record;

end Base_Class.Child_Class ;

Now the child package would have full knowledge of what is inside the 
private part of the Base_Class package and could reference the AAA field.

Note that there are reasons you may not want to do that. Gaining 
visibility to the private part of the package pretty much violates the 
whole concept of why it was made private in the first place. Generally, 
providing accessor functions for the fields of interest or procedures 
for other operations on the hidden information is a better choice.

I generally like to go to a child package with full visibility of the 
private section in cases where I am conveniently sectioning off 
operations for a class. The parent may have basic accessor & 
construction/destruction operations. One child may provide operations 
for I/O to/from files, another might provide display capabilities, etc. 
Where I do type extension is when I am providing a family of classes to 
the user so they can pick the best one for the job. There is a little 
bit of an art to deciding when something should be a child package and 
when it should not, but you develop a sense for it with some experience 
building larger systems in Ada.

MDC





Ludovic Brenta wrote:
> 
> I don't have all the details of your program, but I suspect that:
> 


-- 
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

     "In general the art of government consists in taking as
     much money as possible from one class of citizens to give
     to the other."

         --  Voltaire
======================================================================




  reply	other threads:[~2003-07-11 11:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-10 20:56 Problems with tagged records and inheritance Papastefanos Serafeim
2003-07-10 22:15 ` Re; " tmoran
2003-07-10 22:24 ` Robert I. Eachus
2003-07-10 22:29 ` Ludovic Brenta
2003-07-11 11:56   ` Marin David Condic [this message]
2003-07-11 11:49 ` Papastefanos Serafeim
2003-07-15  1:34 ` Richard Riehle
replies disabled

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