comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Preventing private procedure visibility being made public through extension
Date: Sun, 21 May 2017 13:21:31 -0700 (PDT)
Date: 2017-05-21T13:21:31-07:00	[thread overview]
Message-ID: <f4506d58-f182-45cf-a3ac-830a6ef790d8@googlegroups.com> (raw)
In-Reply-To: <c17246bf-f314-46e5-9e6a-7ec725cbd61c@googlegroups.com>

On Sunday, May 21, 2017 at 2:14:23 PM UTC-4, Robert Eachus wrote:
> On Saturday, May 20, 2017 at 1:33:27 PM UTC-4, Jere wrote:
> > I tried to whittle this down to a small example, so forgive 
> > the uselessness of the example itself.  I'm extending a 
> > library with some of my own components and I want (if possible) 
> > to allow my components to interact with the other library 
> > components as seamlessly as possible.
> > 
> > Say a library provides a tagged type with the following procedure:
> > 
> > Base.ads
> > *************************************************
> > package Base is
> >    
> >    type Base_Param is tagged null record;
> >    
> >    type Base_Type is tagged null record;
> >    
> >    procedure Something
> >       (Obj : in out Base_Type; 
> >        Value : Base_Param'Class) 
> >    is null;
> >    
> > end Base;
> > 
> > *************************************************
> ...
> I think that the problem you are dealing with is the you 
> started with one package and have never let go of that 
> model.  You have two very different access patterns in 
> mind (not access in the Ada sense).  So you need two 
> packages to declare them.  Is there any reason to allow 
> your clients to do anything with Base_Param other than 
> pass it to subroutines you provide?  I think not.  I’m 
> also going to avoid games like the Taft amendment,  
> Use it if you want to.

Sorry, that was just an example.  The actual use case has 
them in separate packages, but the problem is the same:

1. I want my type to be usable in the 3rd party library, 
   so I need to extend a type from it or provide access
   to an internal parameter of one of its types.
2. I don't want to provide some of the library type's
   public procedures as they can mess up my derived type
   if called.  Per Dmitry's suggestion, I can provide
   runtime safety, but I was looking for static safety.

At the moment I am leaning using an encapsulating type
that passes back an access to an internal component
so I can still interface to the library.  I just don't
like using access types if I can avoid them.

So something like:

   type My_Type is tagged limited private;
   function Get_Libaray_Component
      (Obj : in out My_Type)
      return not null access Library_Type;
private
   type My_Type is new Other_Library_Type with record
      Base : aliased Library_Type;
   end record;

Then I can call:
Library.Some_Library_Function(My_Var.Get_Library_Component.all);

But none of Other_Library_Type's procedures can be publicly 
called on my extended type, breaking it.

Note that the library I am interfacing with already exists
and is not mine.  I don't want to modify it or else any
code I augment it with won't be usable to others without
them modding their copies as well.


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