From: Natasha Kerensikova <lithiumcat@instinctive.eu>
Subject: How to hide inherited implementation of a public interface?
Date: Fri, 21 Mar 2014 12:53:45 +0000 (UTC)
Date: 2014-03-21T12:53:45+00:00 [thread overview]
Message-ID: <slrnliodi3.i0l.lithiumcat@nat.rebma.instinctive.eu> (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
next reply other threads:[~2014-03-21 12:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-21 12:53 Natasha Kerensikova [this message]
2014-03-21 13:54 ` How to hide inherited implementation of a public interface? 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox