comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: OOP in Ada: Alternatives for "protected" scope
Date: Sat, 5 May 2012 13:53:59 +0200
Date: 2012-05-05T13:53:59+02:00	[thread overview]
Message-ID: <hu3l1msk42yo$.14kbjfv94ermy$.dlg@40tude.net> (raw)
In-Reply-To: jo2obr$tln$1@online.de

On Sat, 5 May 2012 10:28:43 +0200, Felix Krause wrote:

> Yes, but that's not what I wanted. Let's have a more specific example 
> using orthogonal inheritance:
> 
> package P is
>    type A is tagged private;
>    -- ...
> end P;
> 
> generic
>    type Base is new A with private;
> package P.Extend is
>    type Extended is new Base with private;
>    -- ...
> end P.Extend;
> 
> package P.Q is
>    type B is new A with private;
>    -- ...
> end P.Q;
> 
> package P.Q.R is
>    package B_Extend is new P.Extend (Base => B);
>    type C is new B_Extend.Extended with private;
> end P.Q.R;
> 
> (I actually have some code with this structure.) I cannot possibly 
> access the private part of P.Extend in P.Q.R - although I'm extending 
> the class defined there.

Extending = use. Using does not give special rights on the content! (:-))
The idea is that you create derived types in a way independent on the
implementation of the parent. If the provider of the parent hid some stuff
in the private part, there must be a good reason why nobody should look
after.

BTW, things hidden in the bodies are inaccessible by any means. My attitude
to "private" is to treat it as a compromise helping the compiler to know
what it should know, rather than a design tool to give access to children.
Ideally, the private part should contain only things which cannot be moved
to the body due to language constraints.

> I cannot layout the packages in a way that 
> lets me access both P.Extend's and P.Q's private part in P.Q.R.

Are you constructing the dreadful Rhombus? (:-))

If a package need to see internals of two packages it must be a descendant
of both. This makes it generic if one of them is.

   package P is
      type A is tagged private;
      -- ...
   end P;

   package P.Q is
   type B is new A with private;
      -- ...
   end P.Q;

   generic
      type Base is new A with private;
   package P.Q.Extend is
      type Extended is new Base with private;
      -- ...
   end P.Q.Extend;

   generic
   package P.Q.Extend.R is
      type C is new Extended with private;
   end P.Q.Extend.R;

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



  reply	other threads:[~2012-05-05 11:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-03 21:27 OOP in Ada: Alternatives for "protected" scope Felix Krause
2012-05-03 21:56 ` Dmitry A. Kazakov
2012-05-04 18:48   ` Felix Krause
2012-05-04 22:00     ` Dmitry A. Kazakov
2012-05-05  8:28       ` Felix Krause
2012-05-05 11:53         ` Dmitry A. Kazakov [this message]
2012-05-05  4:33     ` Shark8
2012-05-03 23:34 ` Randy Brukardt
2012-05-04  1:41 ` BrianG
2012-05-04 10:37 ` Georg Bauhaus
2012-05-04 10:43   ` Georg Bauhaus
2012-05-04 12:10   ` Dmitry A. Kazakov
replies disabled

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