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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,66f9ac28e8d63f60 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!m38g2000yqd.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Enforcing initialization protocol for protected type Date: Mon, 7 Sep 2009 13:19:02 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <1fcccc80-0142-4f07-8852-8d151ea96ee2@c37g2000yqi.googlegroups.com> <4aa53c59$0$30237$9b4e6d93@newsspool1.arcor-online.net> NNTP-Posting-Host: 83.76.205.140 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1252354742 9042 127.0.0.1 (7 Sep 2009 20:19:02 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 7 Sep 2009 20:19:02 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m38g2000yqd.googlegroups.com; posting-host=83.76.205.140; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8219 Date: 2009-09-07T13:19:02-07:00 List-Id: On 7 Wrz, 19:01, Georg Bauhaus wrote: > The following is not using, I guess, your original > idea directly. =A0But it requires that the a proper context > be set up. =A0Then, the PO will initialize itself from > the context. =A0Context is passed in via known discriminants: [...] I see. I guess that in addition to passing the factory (function on object, as in your example), the state itself can be passed via discriminant as well. This would leave the factory call at the user side (note that in your example it was the protected object itself that called the factory), which would give more control on factory call parameters and such. type State is private; type State_Ptr is access State; function Make_PO return State_Ptr; function Make_PO (Some : T; Parameters : T) return State_Ptr; -- ... protected type PO (S : State_Ptr) is -- ... private St : State_Ptr :=3D S; end PO; so that the typical creation pattern would be: X : PO (Make_PO); Y : PO (Make_PO (ABC, DEF)); This, however, opens another question: controlled finalization of protected types to release the state object, if it was allocated dynamically. Oops. But a controlled component of the protected type can take care of that. Does it make sense? -- Maciej Sobczak * www.msobczak.com * www.inspirel.com Database Access Library for Ada: www.inspirel.com/soci-ada