From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Preventing private procedure visibility being made public through extension Date: Sat, 20 May 2017 22:32:04 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: BYuA7L7MRjuLLjcoGHOBxw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:46826 Date: 2017-05-20T22:32:04+02:00 List-Id: 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