comp.lang.ada
 help / color / mirror / Atom feed
* Protected types private part visibility , helpfull hints needed.
       [not found] <20050428025529.717ED4C40D8@lovelace.ada-france.org>
@ 2005-04-28 11:30 ` Christopher Gosset
  2005-04-28 12:16   ` Dmitry A. Kazakov
  2005-04-29  3:03   ` Jeffrey Carter
  0 siblings, 2 replies; 4+ messages in thread
From: Christopher Gosset @ 2005-04-28 11:30 UTC (permalink / raw)
  To: comp.lang.ada

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 ! 

Is there a reason behind this design? 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
? 

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! 

Am I correct in my assumptions or is there something I have missed? 

Helpfull hints will be appriciated! 


/CG















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

* Re: Protected types private part visibility , helpfull hints needed.
  2005-04-28 11:30 ` Protected types private part visibility , helpfull hints needed Christopher Gosset
@ 2005-04-28 12:16   ` Dmitry A. Kazakov
  2005-04-29  3:03   ` Jeffrey Carter
  1 sibling, 0 replies; 4+ messages in thread
From: Dmitry A. Kazakov @ 2005-04-28 12:16 UTC (permalink / raw)


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



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

* Re: Protected types private part visibility , helpfull hints needed.
       [not found] <000101c54be5$a4aad420$9500000a@amd2600>
@ 2005-04-29  1:22 ` Stephen Leake
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2005-04-29  1:22 UTC (permalink / raw)
  To: Christopher Gosset; +Cc: comp.lang.ada

"Christopher Gosset" <chrg@online.no> writes:

> 	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
>>-------

Ada 2006 has a 'private with' context clause that will help here.


-- 
-- Stephe




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

* Re: Protected types private part visibility , helpfull hints needed.
  2005-04-28 11:30 ` Protected types private part visibility , helpfull hints needed Christopher Gosset
  2005-04-28 12:16   ` Dmitry A. Kazakov
@ 2005-04-29  3:03   ` Jeffrey Carter
  1 sibling, 0 replies; 4+ messages in thread
From: Jeffrey Carter @ 2005-04-29  3:03 UTC (permalink / raw)


You're quite right: any types referenced in the private part of the 
protected type must be publicly visible in the enclosing package spec. 
I'm not sure if the "private with" of Ada 0X will apply in this case; I 
recall that it only allows references in the private part of the package.

FWIW, the following compiles:

package Private_Protected_Private is
    type Implementation is limited private;

    protected type Pt is
       procedure Op (I : in Integer);
    private -- Pt
       Value : Implementation;
    end Pt;
private -- Private_Protected_Private
    type Implementation is ...;
end Private_Protected_Private;

This allows the types used in the private part of the protected type to 
be private to clients of the package.

-- 
Jeff Carter
"Beyond 100,000 lines of code you
should probably be coding in Ada."
P. J. Plauger
26



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

end of thread, other threads:[~2005-04-29  3:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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
2005-04-29  3:03   ` Jeffrey Carter
     [not found] <000101c54be5$a4aad420$9500000a@amd2600>
2005-04-29  1:22 ` Stephen Leake

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