From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Preventing private procedure visibility being made public through extension
Date: Sat, 20 May 2017 22:32:04 +0200
Date: 2017-05-20T22:32:04+02:00 [thread overview]
Message-ID: <ofq943$14v4$1@gioia.aioe.org> (raw)
In-Reply-To: bd5b3107-709d-46b9-b29b-fd15e8a6e265@googlegroups.com
On 2017-05-20 19:33, Jere wrote:
> package Derived is
>
> type Derived_Param is new Base.Base_Param with null record;
>
> type Derived_Type is new Base.Base_Type with private;
>
> procedure Something
> (Obj : in out Derived_Type;
> Value : Derived_Param'Class)
> is null;
>
> type More_Derived_Type is new Derived_Type with private;
>
> private
>
> type Derived_Type is new Base.Base_Type with null record;
>
> overriding
> procedure Something
> (Obj : in out Derived_Type;
> Value : Base.Base_Param'Class)
> is null;
This is not private regardless where it appears. When you derive from
Base_Type that automatically declares Something for Derived_Type. You
may override its body but that is all you can do. When you declare
another Something for Derived_Param'Class that overloads the already
inherited Something and here you are.
> Is there a way for me to prevent extending types from making
> the procedure public again?
It is public. That was the decision made in the package Base. The
package Derived has no say on that.
----------------------------------
The actual problem you have is parallel types hierarchies. You want to
derive tied instances of Base_Type'Class and Base_Param'Class.
Base_Type ----- Base_Param
| |
Derived_Type -- Derived_Param
This requires
1. Full multiple dispatch
2. Dispatch constrained to certain combinations (parallel hierarchies)
This is not supported in Ada (or in any other OO language I am aware of)
A typical workaround is replacing multiple dispatch (pos.1) with a
cascaded dispatch. I.e. you keep Something class-wide in the second
parameter. Then you override it as you did. In the body you select the
parameter type in any desired way (second dispatch).
The drawback is obviously loss of static type checks (pos.2):
procedure Something
( Obj : in out Derived_Type;
Value : Base_Param'Class
) is
begin
if not Value in Derived_Param then -- or a more relaxed
-- Derived_Param'Class
raise Constraint_Error with "Value type error";
end if;
declare
Checked_Value : Derived_Param renames Derived_Param (Value);
begin
... -- Go on
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2017-05-20 20:32 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-20 17:33 Preventing private procedure visibility being made public through extension Jere
2017-05-20 20:13 ` AdaMagica
2017-05-20 21:55 ` Jere
2017-05-20 20:32 ` Dmitry A. Kazakov [this message]
2017-05-20 22:51 ` Jere
2017-05-21 0:51 ` Jere
2017-05-21 9:16 ` Chris Moore
2017-05-21 22:55 ` Jere
2017-05-21 8:44 ` Dmitry A. Kazakov
2017-05-21 12:19 ` J-P. Rosen
2017-05-21 12:53 ` Dmitry A. Kazakov
2017-05-21 20:06 ` Jere
2017-05-21 21:07 ` Dmitry A. Kazakov
2017-05-21 22:28 ` Jere
2017-05-22 8:52 ` Dmitry A. Kazakov
2017-05-22 13:33 ` AdaMagica
2017-05-22 13:43 ` AdaMagica
2017-05-22 21:17 ` Randy Brukardt
2017-05-25 4:06 ` Jere
2017-05-25 19:39 ` Randy Brukardt
2017-05-25 22:53 ` Jere
2017-05-25 22:57 ` Jere
2017-05-26 20:46 ` Randy Brukardt
2017-05-26 22:35 ` Simon Wright
2018-05-20 11:22 ` Simon Wright
2018-05-20 12:03 ` Jere
2017-05-26 22:58 ` Jeffrey R. Carter
2017-05-30 21:15 ` Randy Brukardt
2017-06-02 1:07 ` Jere
2017-06-02 7:31 ` Dmitry A. Kazakov
2017-06-02 8:09 ` Mark Lorenzen
2017-06-02 11:31 ` Simon Wright
2017-05-22 21:12 ` Randy Brukardt
2017-05-23 7:38 ` Dmitry A. Kazakov
2017-05-21 18:14 ` Robert Eachus
2017-05-21 20:21 ` Jere
2017-05-21 21:09 ` Jeffrey R. Carter
2017-05-21 22:46 ` Jere
2017-05-22 21:24 ` Jeffrey R. Carter
2017-05-25 3:45 ` Jere
2017-05-21 21:20 ` Dmitry A. Kazakov
2017-05-21 21:45 ` Jere
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox