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.107.8.26 with SMTP id 26mr23923155ioi.27.1511812603534; Mon, 27 Nov 2017 11:56:43 -0800 (PST) X-Received: by 10.157.42.99 with SMTP id t90mr1701490ota.5.1511812603463; Mon, 27 Nov 2017 11:56:43 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.am4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!i6no7675044itb.0!news-out.google.com!193ni4838iti.0!nntp.google.com!i6no7675037itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 27 Nov 2017 11:56:43 -0800 (PST) In-Reply-To: <24767ee5-cda8-45e4-98d1-7da44757bd40@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.208.22; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.208.22 References: <4db43571-7f86-4e73-8849-c41160927703@googlegroups.com> <6496a10f-c97e-4e42-b295-2478ad464b2f@googlegroups.com> <6106dfe6-c614-4fc1-aace-74bf8d7435e3@googlegroups.com> <24767ee5-cda8-45e4-98d1-7da44757bd40@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Extending a third party tagged type while adding finalization From: Jere Injection-Date: Mon, 27 Nov 2017 19:56:43 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 5160 X-Received-Body-CRC: 104149943 Xref: reader02.eternal-september.org comp.lang.ada:49195 Date: 2017-11-27T11:56:43-08:00 List-Id: On Monday, November 27, 2017 at 1:10:57 PM UTC-5, Shark8 wrote: > On Sunday, November 26, 2017 at 10:33:50 AM UTC-7, Jere wrote: > > > > What I tried to do was use a mixin but have it keep a reference to a > > classwide access on the object. Then I tried dispatching out to the > > correct object type from there. This kind of highlighted the evils > > of using redispatch in Ada though as I found that if I had component > > definitions like this: > > JP Rosen's paper "A Naming Convention for Classes in Ada 9X" details a way you might be able to ease the pain of such constructs. > > The example of adding a "with benefits" extension to "computer scientist" which is itself an "employee" is detailed as follows: > with Employee; use Employee; > generic > type Origin is new Employee.lnstance with private; > packaqe With_Benefits_Facet is > type Instance is new Origin with private; > subtype Class is Instance'Class; > > -- Operations to handle benefits private > end With__Benefits_Facet; > > -------------------------------- > > with Computer__Scientist, With_Benefits_Facet; use Computer_Scientist; > package Computer_Scientists__With__Benefits is > new With__Benefits__Facet(Computer_Scientist. Instance); > > > So, to do this sort of thing how you want, couldn't you handle things via generic? > > Generic > -- You might want to put a Base here and derive from it... > Type Controlled is limited private; > with procedure Initialize (Object : in out Controlled) is null; > with procedure Adjust (Object : in out Controlled) is null; > with procedure Finalize (Object : in out Controlled) is null; > Package Controlled_Mixin is > > Type Instance is new Ada.Finalization.Limited_Controlled with record > Component : Controlled; > end record; > > --... > End Controlled_Mixin; > Well the initial intent is that I am integrating someone else's third party library which uses a lot of classwide parameters. Normally I would just extend the base type and do something similar to what you and AdaMagica have proposed. what I am trying to avoid is having to do this for every descendant down the line. I wanted to remove as much of the burden that I can from any client code. While having to do a separate mixin for every descendant isn't the end of the world, I was hoping there was a way to do a single mixin and have it propogate via inheritance to all later descendants. That way a user doesn't have to do the mixin for every new type. I was just trying to reduce a lot of package noise. With the mixin approach I would need to do something like: type New_Type1 is new Base_Type with private; procedure Initialize(Self : in out New_Type1); procedure Finalize (Self : in out New_Type1); package New_Type1_To_LC is new To_Limited_Controlled(New_Type1,Initialize,Finalize); subtype New_Type1_LC is New_Type1_LC.Controlled; type New_Type2 is new New_Type1_LC with private; procedure Initialize(Self : in out New_Type2); procedure Finalize (Self : in out New_Type2); package New_Type2_To_LC is new To_Limited_Controlled(New_Type2,Initialize,Finalize); subtype New_Type2_LC is New_Type2_LC.Controlled; VS with some (undiscovered) inheritance method: package Limited_Controlled is new My_Limited_Controlled(Base_Type); subtype Controlled is Limited_Controlled.Controlled; type New_Type1 is new Controlled with private; overriding procedure Finalize (Self : in out New_Type1); type New_Type2 is new New_Type1_LC with private; overriding procedure Finalize (Self : in out New_Type2); In the former method, I have to define dummy procedures and do a mixin for every new type. In the latter method, I only have to do it once and just inherit and override as necessary.