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

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