comp.lang.ada
 help / color / mirror / Atom feed
* Hiding details and protected types
@ 2007-04-24 13:44 Maciej Sobczak
  2007-04-24 15:04 ` Jean-Pierre Rosen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Maciej Sobczak @ 2007-04-24 13:44 UTC (permalink / raw)


Hi,

Let's say there is a protected type:

protected type PT is
   procedure P;
private
   A : T;
end PT;

where T is some type that is really an implementation detail of PT.

It is not possible to declare this type in the private part of the 
protected type (why?), so it has to be declared outside PT:

type T is ...;
protected type PT is
   procedure P;
private
   A : T;
end PT;

The problem is that declaring T in the same declaration scope pollutes 
the name space and is against Good Engineering Principles (tm).

How can I hide it?
Some juggling with packages comes to mind - any recommendations?

-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



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

* Re: Hiding details and protected types
  2007-04-24 13:44 Hiding details and protected types Maciej Sobczak
@ 2007-04-24 15:04 ` Jean-Pierre Rosen
  2007-04-24 18:18   ` Randy Brukardt
  2007-04-24 19:16 ` Jeffrey R. Carter
  2007-04-24 21:31 ` Georg Bauhaus
  2 siblings, 1 reply; 5+ messages in thread
From: Jean-Pierre Rosen @ 2007-04-24 15:04 UTC (permalink / raw)


Maciej Sobczak a �crit :

> It is not possible to declare this type in the private part of the 
> protected type (why?), 
Because a protected type is like a record, not like a package.
You can only declare protected operations and components inside it.

-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



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

* Re: Hiding details and protected types
  2007-04-24 15:04 ` Jean-Pierre Rosen
@ 2007-04-24 18:18   ` Randy Brukardt
  0 siblings, 0 replies; 5+ messages in thread
From: Randy Brukardt @ 2007-04-24 18:18 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1093 bytes --]

"Jean-Pierre Rosen" <rosen@adalog.fr> wrote in message
news:aa6l0f.5ji.ln@hunter.axlog.fr...
> Maciej Sobczak a �crit :
>
> > It is not possible to declare this type in the private part of the
> > protected type (why?),
> Because a protected type is like a record, not like a package.
> You can only declare protected operations and components inside it.

Which only begs the question, why can't you declare a type inside of a
record? Sometimes it would be convenient to do so:
    type Foobar is record
         A : array (1..10) of Integer; -- Illegal!
    end record;

The *real* answer to the question is that Ada does not allow intertwined
type declarations. That's because those bring up all kinds of weird
visibility issues for the predefined operators of the inner type. We don't
want operators being defined in the middle of a record type! You might note
that anonymous access types are allowed in these contexts, but that is OK
because they don't have any operators of their own (thus no complications
deciding where they are defined).

                               Randy.







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

* Re: Hiding details and protected types
  2007-04-24 13:44 Hiding details and protected types Maciej Sobczak
  2007-04-24 15:04 ` Jean-Pierre Rosen
@ 2007-04-24 19:16 ` Jeffrey R. Carter
  2007-04-24 21:31 ` Georg Bauhaus
  2 siblings, 0 replies; 5+ messages in thread
From: Jeffrey R. Carter @ 2007-04-24 19:16 UTC (permalink / raw)


Maciej Sobczak wrote:
> 
> It is not possible to declare this type in the private part of the 
> protected type (why?), so it has to be declared outside PT:
> 
> type T is ...;
> protected type PT is
>   procedure P;
> private
>   A : T;
> end PT;
> 
> The problem is that declaring T in the same declaration scope pollutes 
> the name space and is against Good Engineering Principles (tm).

I agree. You can't hide the existence of T, but you can usually hide its 
details:

    type T is private;

    protected type P is
       ...
private
    type T is ...;

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



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

* Re: Hiding details and protected types
  2007-04-24 13:44 Hiding details and protected types Maciej Sobczak
  2007-04-24 15:04 ` Jean-Pierre Rosen
  2007-04-24 19:16 ` Jeffrey R. Carter
@ 2007-04-24 21:31 ` Georg Bauhaus
  2 siblings, 0 replies; 5+ messages in thread
From: Georg Bauhaus @ 2007-04-24 21:31 UTC (permalink / raw)


On Tue, 2007-04-24 at 15:44 +0200, Maciej Sobczak wrote:

> How can I hide it?
> Some juggling with packages comes to mind - any recommendations?

For protected objects,

package PO is

   procedure put(item: Integer);
   function get return Integer;

private

   type More_Complex_Integer is
      record
         odd: Boolean;
      end record;

   protected Orderly is
      procedure put(item: Integer);
      function get return Integer;
   private
      data: More_Complex_Integer;
   end Orderly;

   procedure put(item: Integer) renames Orderly.put;
   function get return Integer renames Orderly.get;

end PO;





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

end of thread, other threads:[~2007-04-24 21:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-24 13:44 Hiding details and protected types Maciej Sobczak
2007-04-24 15:04 ` Jean-Pierre Rosen
2007-04-24 18:18   ` Randy Brukardt
2007-04-24 19:16 ` Jeffrey R. Carter
2007-04-24 21:31 ` Georg Bauhaus

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