comp.lang.ada
 help / color / mirror / Atom feed
From: Jim Rogers <jimmaureenrogers@worldnet.att.net>
Subject: Re: scope and visibility
Date: Wed, 27 Feb 2002 15:19:44 GMT
Date: 2002-02-27T15:19:44+00:00	[thread overview]
Message-ID: <3C7CF8EF.7030907@worldnet.att.net> (raw)
In-Reply-To: 3C7C59CE.7040104@users.sf.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".

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




  reply	other threads:[~2002-02-27 15:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-27  4:00 scope and visibility Dave Poirier
2002-02-27 15:19 ` Jim Rogers [this message]
2002-02-27 22:47   ` chris.danx
  -- strict thread matches above, loose matches on Subject: below --
2002-02-27  7:00 Christoph Grein
replies disabled

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