comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Protected types private part visibility , helpfull hints needed.
Date: Thu, 28 Apr 2005 14:16:56 +0200
Date: 2005-04-28T14:16:56+02:00	[thread overview]
Message-ID: <3ecghis18u1q$.dxtujoestjq.dlg@40tude.net> (raw)
In-Reply-To: mailman.97.1114687832.24457.comp.lang.ada@ada-france.org

On Thu, 28 Apr 2005 13:30:12 +0200, Christopher Gosset wrote:

> I am making a library consisting of several packages.
> I wished to make all memory management and other "house-holding"
> functions private by having them in private packages and to make all
> details that is not a part of the "client-view" private.
> 
> So I have a package spec with a  protected type that look something like
> this
> 
> 	Generic 
> 	Type Item_Type (<>) is Private ;
> 
> 	Package Protected_List is 
> 
> 	Protected Type List is 
> 	
> 	Procedure  Add( Item : In Item_Type) ;
> 	Function Item(Index : In Positive) Return Item_Type ;
> 
> 	Private 
> 
> 		Internal_List_Structure : Internal_List ; ----------<
> This is the problem line I would like the internal list structure to be
> declared in a PRIVATE package and be visible to this private part
>>-------
> 
> 	End List ;
> 
> 	Private 
> 	Type Item_Pointer is Access Item_Type ;
> 
> 	End Protected_List ;
> 
> This does not work! This is because the Private part of the Protected
> Type Declaration is a PART OF THE PUBLIC PART OF THE PACKAGE SPEC ! 

It is only nominally there.

> Is there a reason behind this design?

Well, protected and task types break Ada's design which otherwise carefully
separates scopes and types. For both there are reasons why. As for
protected types, their members need to be safe(protected) from any access
other than through the operations of the type. The visibility here is
simply not determined by the enclosing package. If you want something
comparable then consider it is as a nested package. You can't access its
private part from outside (except from children of course.) Maybe it would
be better to have protected objects and packages instead of objects and
types.

> Wouldn't it be more reasonable
> that the private part of a Protected Type should be a part of the
> PRIVATE part of the package spec and thus be able to use types and
> procedures declared in private packages and private parts of the parent
> ? 

It would be reasonable for all record-like types to have private members
(declared in the private package part.) Presently only non-primitive
operations can be made private. Abstract primitive operations and entry
points cannot be.

> The private part of the protected type should never be visible to the
> client anyway and the fact that all types and pakcages used in the
> protected type private part must be Public destroys my absctraction! 

There are also numerous other cases. For example: the default value of a
parameter cannot be hidden. Tagged type cannot be extended by adding both
public and private members etc.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-04-28 12:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20050428025529.717ED4C40D8@lovelace.ada-france.org>
2005-04-28 11:30 ` Protected types private part visibility , helpfull hints needed Christopher Gosset
2005-04-28 12:16   ` Dmitry A. Kazakov [this message]
2005-04-29  3:03   ` Jeffrey Carter
     [not found] <000101c54be5$a4aad420$9500000a@amd2600>
2005-04-29  1:22 ` Stephen Leake
replies disabled

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