comp.lang.ada
 help / color / mirror / Atom feed
* scope and visibility
@ 2002-02-27  4:00 Dave Poirier
  2002-02-27 15:19 ` Jim Rogers
  0 siblings, 1 reply; 4+ messages in thread
From: Dave Poirier @ 2002-02-27  4:00 UTC (permalink / raw)


this is most certainly a FAQ one, but, I've been reading the Lovelace 
tutorial, tried reading chapter 8 of the ALRM and read the part 
concerning visibility in Ada Distilled.

I understand the difference between 'with' and 'use', that's no problem, 
but I'm having quite a hard time with 'private' and friends.  Is there 
any tutorial detailing from side-to-side how those work for ada-newbies?

The chapter 8 of the ALRM is definately complete but is so full of Ada 
terms that I'd have to spend 10 days pulling my hair going from side to 
side of the book to figure it out.  Most Ada-newbie tutorial teaches you 
how to write basic apps skimming visibility (mostly talk about with/use 
and that's it).

Any url, doc, explanation whatever would be greatly appreciated.  I've 
been trying for the past 4 hours to created a Bounded_String and just 
can't get it.

Thanks,
EKS - Dave Poirier.


note: something nice full of examples using the Ada libraries, with both 
working and non-working examples for all possible combinations and why 
they [don't] work...




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: scope and visibility
@ 2002-02-27  7:00 Christoph Grein
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Grein @ 2002-02-27  7:00 UTC (permalink / raw)


> but I'm having quite a hard time with 'private' and friends.

The Ada keyword 'private' means that you do not see into the thing denoted as 
private.

Thus a private type hides its details, you do not see them and cannot assume 
anything about them.
'private' in a package hides anything behind from visibility outside this 
hierarchy.

package P is

  type T is private;

  ...operations...

private

  type T is new Integer;

end P;

If you're outside of P, you cannot make use of the fact that T is an integer. It 
could be anything (array, record, ...) that is not limited (another Ada 
keyword).

Inside of P, after the keyword 'private' and also in the body, you of course can 
use the fact that T is Integer. This is also true for children of P.

private package P.Priv_Child is

  -- You see the private part of P here.

private

end P.Priv_Child;

package P.Child is

  -- You do not see the private part of P here.

private

  -- You see the private part of P here.

end P.Child;

This is approximately like (but there _are_ differences):

package P is

  type T is private;

  ...operations...

  package Child is
    ...
  end Child;

private

  type T is new Integer;

  package Priv_Child is
    ...
  end Priv_Child;

end P;



Now try

package P.Priv_Child.Grand_Child is ...

private P.Priv_Child.Priv_Grand_Child is ...

package P.Child.Grand_Child is ...

private P.Child.Priv_Grand_Child is ...

These all have different visibilities.


generic
  type T is private;
package P is
  -- You cannot assume anything about P except that it's not limited and
  -- that it is definite.
end P;



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: scope and visibility
  2002-02-27  4:00 Dave Poirier
@ 2002-02-27 15:19 ` Jim Rogers
  2002-02-27 22:47   ` chris.danx
  0 siblings, 1 reply; 4+ messages in thread
From: Jim Rogers @ 2002-02-27 15:19 UTC (permalink / raw)


Dave Poirier wrote:

> I understand the difference between 'with' and 'use', that's no problem, 
> but I'm having quite a hard time with 'private' and friends.  Is there 
> any tutorial detailing from side-to-side how those work for ada-newbies?


When you use the term "friends" I assume you are looking at Ada from a
C++ point of view. Technically, Ada does not have "friends".

Ada does have a hierarchical package structure which allows much
of the visibility you expect from "friends".

Ada "private" declarations are closest to C++ and Java "protected"
declarations. Any item declared first in a package body is
closest to a C++ or Java "private" declaration.

A child package has direct visibility to its parent package in
the following manner:

The public part of the child package has visibility to the public
part of the parent package.

The private part of the child package has visibility to the
public and private parts of the parent package.

The child package has NO visibility to the items declared in the
parent's package body.

One difference between Ada hierarchical packages and C++ friends
is that the Ada parent package does not need to be modified to
allow access from the child. In C++ a class must declare its
friends. In real programming this often causes the C++ developer
to modify the "parent" class to allow friendship. Such
modifications can be expensive in a maintenance environment where
several products already depend on the compilation unit containing
the "parent" class. In Ada, the parent package is never modified
to allow a child class. This simplifies maintenance issues by not
requiring a change to released compilation units.

Jim Rogers




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: scope and visibility
  2002-02-27 15:19 ` Jim Rogers
@ 2002-02-27 22:47   ` chris.danx
  0 siblings, 0 replies; 4+ messages in thread
From: chris.danx @ 2002-02-27 22:47 UTC (permalink / raw)



"Jim Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
news:3C7CF8EF.7030907@worldnet.att.net...
> Dave Poirier wrote:
>
> > I understand the difference between 'with' and 'use', that's no problem,
> > but I'm having quite a hard time with 'private' and friends.  Is there
> > any tutorial detailing from side-to-side how those work for ada-newbies?
>
>
> When you use the term "friends" I assume you are looking at Ada from a
> C++ point of view. Technically, Ada does not have "friends".

I think Dave means something like "private & co.", like private and related
issues/concepts, not friends as in C++.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-02-27 22:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-27  7:00 scope and visibility Christoph Grein
  -- strict thread matches above, loose matches on Subject: below --
2002-02-27  4:00 Dave Poirier
2002-02-27 15:19 ` Jim Rogers
2002-02-27 22:47   ` chris.danx

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