comp.lang.ada
 help / color / mirror / Atom feed
* How to hide inherited implementation of a public interface?
@ 2014-03-21 12:53 Natasha Kerensikova
  2014-03-21 13:54 ` Dmitry A. Kazakov
  2014-03-21 17:58 ` Jeffrey Carter
  0 siblings, 2 replies; 7+ messages in thread
From: Natasha Kerensikova @ 2014-03-21 12:53 UTC (permalink / raw)


Hello,

the subject contains my whole question, but since I'm afraid it might be
ambiguous, let's consider the basic code below:

   package I is
      type T is interface;
      procedure P (Object : in out T) is abstract;
   end I;

   package A is
      type T is abstract new I.T with private;
      function F (Object : in T) return Integer is abstract;
      overriding procedure P (Object : in out T);
   private
      type A is abstract new I.T with record
         Value : Integer;
      end record;
   end A;

   package body A is
      overriding procedure P (Object : in out T) is
         Object.Value := F (T'Class (Object));
      end P;
   end A;

   package C is
      type T is new I.T with private;
      --  What here?
   private
      type T is new A.T with record
         High : Boolean;
      end record
      overriding function F (Object : in T) return Integer;
   end C;

   package body C is
      overriding function F (Object : in T) return Integer is
      begin
         case Object.High is
            when True => return 1;
            when False => return -1;
         end case;
      end F;
   end C;

There is a concrete type C.T, that publicly provides interface I.T, but
internally uses inheritance to implement the interface. The fact that
A.T is abstract is not directly relevant, I believe the situation is
exactly the same with a concrete A.T, but it leaks the motivation behind
such a construction.

I could publicly derive C.T from A.T, and then everything would be fine.

However in the particular case I encountered, it bothers me a bit to
expose publicly that C.T is derived from A.T, since it really is an
implementation detail. The only piece of information available to
clients of C is supposed to be that I.T is implemented, no matter how.

So is there a way to publicly provide I.T while privately inheriting
almost everything from A.T?


Thanks for your help,
Natasha


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

* Re: How to hide inherited implementation of a public interface?
  2014-03-21 12:53 How to hide inherited implementation of a public interface? Natasha Kerensikova
@ 2014-03-21 13:54 ` Dmitry A. Kazakov
  2014-03-21 16:05   ` Natasha Kerensikova
  2014-03-21 17:58 ` Jeffrey Carter
  1 sibling, 1 reply; 7+ messages in thread
From: Dmitry A. Kazakov @ 2014-03-21 13:54 UTC (permalink / raw)


On Fri, 21 Mar 2014 12:53:45 +0000 (UTC), Natasha Kerensikova wrote:

> So is there a way to publicly provide I.T while privately inheriting
> almost everything from A.T?

Where is a problem? If I understand your example right, A.T publicly
implements I.T. This sort of stuff is directly supported since Ada 95. Ada
95 inheritance is idempotent which includes Ada 2005 interfaces. You
publicly derive from I.T and privately from its descendant A.T, due to
idempotence declared and inherited I.Ts are considered same. Was this your
concern?

Not supported in Ada are delegation and additive inheritance
(non-idempotent).

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


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

* Re: How to hide inherited implementation of a public interface?
  2014-03-21 13:54 ` Dmitry A. Kazakov
@ 2014-03-21 16:05   ` Natasha Kerensikova
  0 siblings, 0 replies; 7+ messages in thread
From: Natasha Kerensikova @ 2014-03-21 16:05 UTC (permalink / raw)


On 2014-03-21, Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
> On Fri, 21 Mar 2014 12:53:45 +0000 (UTC), Natasha Kerensikova wrote:
>
>> So is there a way to publicly provide I.T while privately inheriting
>> almost everything from A.T?
>
> Where is a problem? If I understand your example right, A.T publicly
> implements I.T.

Actually my problem was that I couldn't find what I was supposed to put
instead of "-- What here?" to make my example work. It didn't
occur to me that nothing was the correct answer, and all my attempts at
declaring subprograms from the interface I.T where rejected by GNAT
(and it still feels a bit weird to publicly declare having an interface
without explicitly declaring any of the associated subprograms).

Actually it almost occurred to me, but my attempt with nothing was
reject by GNAT because I had something like
"type T is new A.T with limited record ..."
which produces a non-obvious error message. I should have investigated
further on the minimal example instead of the real code.

Anyway, problem solved, sorry for the noise /o\


Natasha


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

* Re: How to hide inherited implementation of a public interface?
  2014-03-21 12:53 How to hide inherited implementation of a public interface? Natasha Kerensikova
  2014-03-21 13:54 ` Dmitry A. Kazakov
@ 2014-03-21 17:58 ` Jeffrey Carter
  2014-03-21 20:14   ` Dmitry A. Kazakov
  1 sibling, 1 reply; 7+ messages in thread
From: Jeffrey Carter @ 2014-03-21 17:58 UTC (permalink / raw)


On 03/21/2014 05:53 AM, Natasha Kerensikova wrote:
>
>     package I is
>        type T is interface;
>        procedure P (Object : in out T) is abstract;
>     end I;

"IMHO, Interfaces are worthless."
Randy Brukardt

-- 
Jeff Carter
"That was the most fun I've ever had without laughing."
Annie Hall
43


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

* Re: How to hide inherited implementation of a public interface?
  2014-03-21 17:58 ` Jeffrey Carter
@ 2014-03-21 20:14   ` Dmitry A. Kazakov
  2014-03-21 23:02     ` Randy Brukardt
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry A. Kazakov @ 2014-03-21 20:14 UTC (permalink / raw)


On Fri, 21 Mar 2014 10:58:54 -0700, Jeffrey Carter wrote:

> On 03/21/2014 05:53 AM, Natasha Kerensikova wrote:
>>
>>     package I is
>>        type T is interface;
>>        procedure P (Object : in out T) is abstract;
>>     end I;
> 
> "IMHO, Interfaces are worthless."

Interface is an abstract type. Abstract types are not worthless.

Worthless is the Java's idea that multiple inheritance could become more
useful, less flawed, choose what you want, when restricted to interfaces.

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


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

* Re: How to hide inherited implementation of a public interface?
  2014-03-21 20:14   ` Dmitry A. Kazakov
@ 2014-03-21 23:02     ` Randy Brukardt
  2014-03-22  8:31       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 7+ messages in thread
From: Randy Brukardt @ 2014-03-21 23:02 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:1goz7i2pg8860.1kma3d5vz1fl$.dlg@40tude.net...
> On Fri, 21 Mar 2014 10:58:54 -0700, Jeffrey Carter wrote:
>
>> On 03/21/2014 05:53 AM, Natasha Kerensikova wrote:
>>>
>>>     package I is
>>>        type T is interface;
>>>        procedure P (Object : in out T) is abstract;
>>>     end I;
>>
>> "IMHO, Interfaces are worthless."
>
> Interface is an abstract type. Abstract types are not worthless.
>
> Worthless is the Java's idea that multiple inheritance could become more
> useful, less flawed, choose what you want, when restricted to interfaces.

Exactly. "Abstract types" (which can have components, implementations, etc.) 
are not worthless. The restrictions on interfaces make them worth little. 
("Worthless" is going a bit far, of course, but it makes a good sound bite.) 
The costs of multiple inheritance (which are considerable) make them not 
worth the effort.

Full multiple inheritance CAN be implemented, but it's expensive enough in 
compiler and language complexity that the costs outweight the value. The 
halfway Java-like solution is easier to implement but makes no one happy. We 
should have told the multiple inheritance nuts to forget it, because it 
makes no sense for Ada.

                                                      Randy.




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

* Re: How to hide inherited implementation of a public interface?
  2014-03-21 23:02     ` Randy Brukardt
@ 2014-03-22  8:31       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2014-03-22  8:31 UTC (permalink / raw)


On Fri, 21 Mar 2014 18:02:28 -0500, Randy Brukardt wrote:

> Full multiple inheritance CAN be implemented, but it's expensive enough in 
> compiler and language complexity that the costs outweight the value.

In the real-life project lack I am working on of proper MI led to a massive
cut-and-paste code explosion on the scale 1 to 1000, at least.

> The 
> halfway Java-like solution is easier to implement but makes no one happy. We 
> should have told the multiple inheritance nuts to forget it, because it 
> makes no sense for Ada.

MI is not a language property, it is more of software design. You cannot
get rid of the fact that software engineers will keep on trying to reuse
code, sharing the code implementing file reading in the code of read-only
and read-write files. This is a sound design. It is the opposite [*] that
does not make sense. If the language does not support sound software design
decisions, well, that is what we call a language flaw.

------------
* The standard library is full of flaws caused by not using MI. From minor
issues that Root_Stream_Type does not implement Limited_Controled, to
massive mess that Character and Wide_Character to don't share common
interface.

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

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

end of thread, other threads:[~2014-03-22  8:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-21 12:53 How to hide inherited implementation of a public interface? Natasha Kerensikova
2014-03-21 13:54 ` Dmitry A. Kazakov
2014-03-21 16:05   ` Natasha Kerensikova
2014-03-21 17:58 ` Jeffrey Carter
2014-03-21 20:14   ` Dmitry A. Kazakov
2014-03-21 23:02     ` Randy Brukardt
2014-03-22  8:31       ` Dmitry A. Kazakov

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