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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.200.56.172 with SMTP id f41mr9465016qtc.32.1495406766643; Sun, 21 May 2017 15:46:06 -0700 (PDT) X-Received: by 10.157.31.68 with SMTP id x4mr422358otx.19.1495406766597; Sun, 21 May 2017 15:46:06 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!feeder3.usenet.farm!feed.usenet.farm!feeder4.usenet.farm!feeder.usenetexpress.com!feeder1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!t26no773331qtg.1!news-out.google.com!m134ni5210itb.0!nntp.google.com!67no1247000itx.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 21 May 2017 15:46:06 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.201.205; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.201.205 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <05ed8053-be36-4332-8b75-7bca9afd65cc@googlegroups.com> Subject: Re: Preventing private procedure visibility being made public through extension From: Jere Injection-Date: Sun, 21 May 2017 22:46:06 +0000 Content-Type: text/plain; charset="UTF-8" Xref: news.eternal-september.org comp.lang.ada:46847 Date: 2017-05-21T15:46:06-07:00 List-Id: On Sunday, May 21, 2017 at 5:09:59 PM UTC-4, Jeffrey R. Carter wrote: > On 05/21/2017 10:21 PM, Jere wrote: > > > > I just don't > > like using access types if I can avoid them. > > Of course you 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; > > There are a finite number of operations defined for Library_Type, and, as you > said, a smaller number that make sense for your abstraction. So you simply > define equivalent operations for My_Type that call the appropriate operations > for Library_Type with the Base component. No access types, simple, safe, and clear. I'll use a more concrete example here. I created a modal dialog box type for Gnoga. My spec looks like: with Gnoga.Gui.Window; with Gnoga.Gui.View; package Gnoga.Gui.Modal_Dialog is type Dialog_Type is tagged limited private; type Dialog_Access is access all Dialog_Type; type Pointer_To_Dialog_Class is access all Dialog_Type'Class; procedure Create (Dialog : in out Dialog_Type; Parent : in out Gnoga.Gui.Window.Window_Type'Class; ID : in String := ""); private type Dialog_Type is new Gnoga.Gui.View.View_Type with record Main_View : Gnoga.Gui.View.View_Access := null; end record; end Gnoga.Gui.Modal_Dialog; and the body: with Gnoga.Gui.Window; with Gnoga.Gui.Base; with Gnoga.Gui.Element; package body Gnoga.Gui.Modal_Dialog is procedure Create (Dialog : in out Dialog_Type; Parent : in out Gnoga.Gui.Window.Window_Type'Class; ID : in String := "") is use type Gnoga.Gui.View.View_Access; Old_View : Gnoga.Gui.Base.Pointer_To_Base_Class := Parent.Get_View; begin if Dialog.Main_View = null then -- Create the Dialog Gnoga.Gui.View.View_Type(Dialog).Create (Parent => Parent, ID => ID); -- Creating a view using a window as a parent sets the view as the -- window's main view. This line sets it back to the original. Parent.Set_View(Old_View.all); -- Configure the Modal Background Dialog.Fill_Parent; Dialog.Background_Color("Grey"); -- Set the default show/hide state Dialog.Show(False); -- Create the main view of the dialog Dialog.Main_View := new Gnoga.Gui.View.View_Type; Dialog.Main_View.Dynamic; Dialog.Main_View.Create(Dialog); Dialog.Main_View.Background_Color("White"); Dialog.Main_View.Position(Gnoga.Gui.Element.Fixed); -- Center the view as a default Dialog.Center; end if; end Create; end Gnoga.Gui.Modal_Dialog; At this point, I need a clean way to let a client add components (Buttons, forms, etc.) to the dialog box. Adding all the operations to Dialog_Type won't help me since all the components use a Create procedure that takes a Gnoga.Gui.Base.Base_Type'Class parent. I don't want to publicly expose the extension of Dialog_Type since procedures like Create_From_HTML and such will really mess with the Dialog_Type. My initial solution was to add: function Get_View (Dialog : in out Dialog_Type) return Gnoga.Gui.View.View_Access is begin return Dialog.Main_View; end Get_View; which is why you see Main_View declare as an access type internally (it was originally just a Gnoga.Gui.View.View_Type before). I don't like this method and am open to other options. Basically, I need something to pass to the Create procedure for any components added. The other option I was tossing around was to instead add a procedure Add_Component (Dialog : in out Dialog_Type; Object : in out Gnoga.Gui.Base.Basetype'Class); but the problem there is the components still need to call Create on some parent, and for the dialog box to work, I think it needs to be the view in my tagged type. Thoughts?