comp.lang.ada
 help / color / mirror / Atom feed
* Can't hide parts of ADTs in private children
@ 1998-11-09  0:00 David Bowerman
  1998-11-09  0:00 ` Stephen Leake
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Bowerman @ 1998-11-09  0:00 UTC (permalink / raw)


I am implementing an Abstract Data Type (Class) in a package.  The code
goes something like this:

  package Class_X_Package is

    type Class_X is private;
    type Class_X_Ptr is access Class_X;

    ...  operations on objects of type X

  private

    type Class_X is
      record
        Component_A : Type_A;
        Component_B : Type_B;
        ...
      end record;

  end Class_X_Package;

The abstract data type (X) is complex, and Type_A, Type_B, etc hide a
lot of structure within themselves.
I would like to break the package down further, declare the types, and
generally hide the details of, Type_A, Type_B, etc (never intended to be
visible to the client) in private child packages.
But I can't do this because these types are referred to in the private
part of the parent package spec, and this isn't allowed to 'with' its
children.

Can anyone suggest another way of doing it.




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

* Re: Can't hide parts of ADTs in private children
  1998-11-09  0:00 Can't hide parts of ADTs in private children David Bowerman
@ 1998-11-09  0:00 ` Stephen Leake
  1998-11-10  0:00 ` Dale Stanbrough
  1998-11-16  0:00 ` Matthew Heaney
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Leake @ 1998-11-09  0:00 UTC (permalink / raw)


David Bowerman <davidb@syd.csa.com.au> writes:

> I am implementing an Abstract Data Type (Class) in a package.  The code
> goes something like this:
> 
>   package Class_X_Package is
> 
>     type Class_X is private;
>     type Class_X_Ptr is access Class_X;
> 
>     ...  operations on objects of type X
> 
>   private
> 
>     type Class_X is
>       record
>         Component_A : Type_A;
>         Component_B : Type_B;
>         ...
>       end record;
> 
>   end Class_X_Package;
> 
> The abstract data type (X) is complex, and Type_A, Type_B, etc hide a
> lot of structure within themselves.
> I would like to break the package down further, declare the types, and
> generally hide the details of, Type_A, Type_B, etc (never intended to be
> visible to the client) in private child packages.

Why do Type_A, Type_B belong in child packages, instead of in library
packages? In building an ADT, you can use facilities of a library,
while making it clear that the user of your ADT should not use the
library directly. Unless Type_A depends on something else in
Class_X_Package, just put it in its own library level package.

> But I can't do this because these types are referred to in the private
> part of the parent package spec, and this isn't allowed to 'with' its
> children.
> 
> Can anyone suggest another way of doing it.

Alternatively, make Class_X an access type, which allows you to defer
the full type definition to the package body, where you can 'with'
child packages.

-- Stephe




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

* Re: Can't hide parts of ADTs in private children
  1998-11-09  0:00 Can't hide parts of ADTs in private children David Bowerman
  1998-11-09  0:00 ` Stephen Leake
@ 1998-11-10  0:00 ` Dale Stanbrough
  1998-11-16  0:00 ` Matthew Heaney
  2 siblings, 0 replies; 4+ messages in thread
From: Dale Stanbrough @ 1998-11-10  0:00 UTC (permalink / raw)


David Bowerman wrote:

"But I can't do this because these types are referred to in the private
 part of the parent package spec, and this isn't allowed to 'with' its
 children."


Sorry, no solution, but an agreement that this is a problem.

Private normally means that the abstraction lives in the package
spec, and if changed clients have to recompile.

The rules for private packages mean that you can't with a private
package in a public spec, _even if it doesn't publically export
anything from the private package_.

E.g.

   package F is
   end F;

   private package F.Priv is
      type Handy is ...;
   end;

   
   with F.Priv;
   package F.Pub is
      type Public_Handy is private;

   private
      type Public_Handy is new F.Priv.Handy;

   end;


This unfortunately is not allowed because private now has another
meaning of...

   "you don't have to recompile external clients if a private package
    spec is changed"

I would rather have the normal rule of "package spec change means
recompilation of clients", than the existing rule which restricts the
composability of types.

Dale




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

* Re: Can't hide parts of ADTs in private children
  1998-11-09  0:00 Can't hide parts of ADTs in private children David Bowerman
  1998-11-09  0:00 ` Stephen Leake
  1998-11-10  0:00 ` Dale Stanbrough
@ 1998-11-16  0:00 ` Matthew Heaney
  2 siblings, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 1998-11-16  0:00 UTC (permalink / raw)


David Bowerman <davidb@syd.csa.com.au> writes:

> I am implementing an Abstract Data Type (Class) in a package.  The code
> goes something like this:
[snip]

> Can anyone suggest another way of doing it.

Do this:

   package Class_X_Package is
 
     type Class_X is private;
     type Class_X_Ptr is access Class_X;
 
     ...  operations on objects of type X
 
   private

     type Type_A is ...;
     type Type_B is ...;
 
     type Class_X is
       record
         Component_A : Type_A;
         Component_B : Type_B;
         ...
       end record;
 
   end Class_X_Package;


If you prefer, you can declare nested packages

private

   package A_Types is

      type Type_A is private;
   ...
   end A_Types;
   use A_Types;

   package B_Types is
   
      type Type_B is private;
   ...
   end B_Types;
   use B_Types;

   type Class_X is 
      record
         Comp_A : Type_A;
         Comp_B : Type_B;
         ...
      end record;

 end Class_X_Package;






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

end of thread, other threads:[~1998-11-16  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-09  0:00 Can't hide parts of ADTs in private children David Bowerman
1998-11-09  0:00 ` Stephen Leake
1998-11-10  0:00 ` Dale Stanbrough
1998-11-16  0:00 ` Matthew Heaney

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