comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Preventing private procedure visibility being made public through extension
Date: Sun, 21 May 2017 23:07:12 +0200
Date: 2017-05-21T23:07:12+02:00	[thread overview]
Message-ID: <ofsvhu$17t9$1@gioia.aioe.org> (raw)
In-Reply-To: 9cdf04e6-123e-4bd9-b466-77aad00d61bb@googlegroups.com

On 2017-05-21 22:06, Jere wrote:
> On Sunday, May 21, 2017 at 4:44:27 AM UTC-4, Dmitry A. Kazakov wrote:
>> On 2017-05-21 00:51, Jere wrote:
>>> On Saturday, May 20, 2017 at 4:32:07 PM UTC-4, Dmitry A. Kazakov wrote:
>>>> On 2017-05-20 19:33, Jere wrote:
>>> I do know that C++ supports hiding of functions by making them private
>>> in the extending class.
>>
>> No. That is not possible in C++ either. A public method cannot be made
>> private.
>>
>> In general from the OO point of view, a method cannot be removed because
>> it is a property of the class and not of an individual type. It is the
>> contract of the class to have a method Foo. All instances of the class
>> must have this method. If they don't they are not instances of. Period.
>>
>> [To support method disallowing the language must support ad-hoc
>> superclasses, so that one could split an original class into parts to
>> chip the undesired operation away from one part and put the new type in
>> that part instead of the whole original class.]
>>
> The language supports making them private in the context of the
> extending classes.  Take for example:
> 
> class Base{
> public:
>     class Base_Param{};
> 
>     void Something(Base_Param Obj){}

Something is not a method here. If you make it a method [= Ada's 
primitive operation]:

    virtual void Something (Base_Param Obj);

then your code will stop compiling.

In Ada a non-primitive operation could be disallowed by declaring it 
abstract, just the same.

An Ada example corresponding to yours is this:

    package Base is
       type Base_Type is null record;
       procedure Something (X : in out Base_Type);
    end Base;

    package Derived is
       type Derived_Type is new Base_Type;
       procedure Something (X : in out Derived_Type) is abstract;
    end Derived;

    X : Base_Type;
    Y : Derived_Type;
begin
    Something (X);
    Something (Y); -- This won't compile

> You're right, they are not proper constructors.  I haven't found
> anything in Ada yet that gives me that.  At best they are
> initializers.
> 
>>> I really don't like doing this.  I don't like using
>>> access types for one.  It's also doesn't feel like
>>> a very clean way because you have to do something
>>> out of the ordinary just to use the class like it was
>>> meant to be.
>>
>> Aggregation + delegation is a decent thing.
>>
>> If you used anonymous access you would reduce dangers of pointers to zero.
>>
> Definitely.  I am also worried about someone copying the access
> value and holding onto it past the lifetime of the object.

Anonymous access types are difficult to copy. Accessibility rules were 
made to prevent any unsafe copying. So you will have to break them by 
doing X.all'Unchecked_Access.

> Temp : Base := Derived.Get_Base;  -- didn't really want to allow

This is illegal. It must be either

    Copy : Base := Derived.Get_Base.all;

or

    Reference : Base renames Derived.Get_Base.all;

Both are safe, yet have a very different semantics.

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


  reply	other threads:[~2017-05-21 21:07 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
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 [this message]
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