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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!club-internet.fr!feedme-small.clubint.net!feeder1-1.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 10 Sep 2009 19:07:53 +0200 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Enforcing initialization protocol for protected type References: <1fcccc80-0142-4f07-8852-8d151ea96ee2@c37g2000yqi.googlegroups.com> <4aa53c59$0$30237$9b4e6d93@newsspool1.arcor-online.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4aa93269$0$32675$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 10 Sep 2009 19:07:53 CEST NNTP-Posting-Host: d6ff914a.newsspool2.arcor-online.net X-Trace: DXC=X]Gja=2cM?Ik:C4l9A;OcOA9EHlD;3YcB4Fo<]lROoRA^YC2XCjHcbIK[2BKCaJ40M;9OJDO8_SKFNSZ1n^B98iJ:C5KBLT3k3@ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:8273 Date: 2009-09-10T19:07:53+02:00 List-Id: Maciej Sobczak schrieb: > 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 := 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? Yes, state pointer makes sense. OTOH, you could preserve both, copy semantics for the state if copying state makes sense and is desirable, and flexible client side operation of the state factory by defining a two-faced factory interface: - one operation is for the protected object. Returns a computed state value as a "result" of the factory's operation - as many operations as desired for computing this inital state. This is for the factory operators other that the protected object