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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c08a7609345f4e5 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.93.MISMATCH!xlned.com!feeder7.xlned.com!news2.euro.net!feeder.news-service.com!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Limited use for limited with? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <853314bc-0f79-435f-86a5-d7bcdd610731@c10g2000yqh.googlegroups.com> <36e886fa-b272-461f-bf86-a6b18366b64f@i5g2000yqe.googlegroups.com> <1eug9v5h5mf8d$.ud00hrz48lyr.dlg@40tude.net> <67044906-dacc-4526-b3f6-27e5323ab8fc@n3g2000yqb.googlegroups.com> Date: Wed, 29 Sep 2010 09:51:28 +0200 Message-ID: <12chb4kbqt9ln$.zumsv1z9hqvk$.dlg@40tude.net> NNTP-Posting-Date: 29 Sep 2010 09:51:29 CEST NNTP-Posting-Host: 24f57c68.newsspool4.arcor-online.net X-Trace: DXC=X6dNkYWcn7H6PJ?[X6JIXE4IUK On Tue, 28 Sep 2010 14:57:49 -0700 (PDT), Maciej Sobczak wrote: > On 28 Wrz, 15:45, "Dmitry A. Kazakov" > wrote: > >>> Hiding the use of access values behind the scenes (by virtue of tagged >>> types being always passed by reference) would obstruct the code >>> without clear benefit. >> >> The benefit is clear - no access types. > > There are still access types. The fact that they are not explicitly > seen in operation signatures just makes it more obscure. No, that makes it (the public interface) more clear. Pointer is an implementation detail to be hidden. > Consider: > > procedure Register (X : in Object'Class); > > X will be passed by reference, but there is still nothing in the > signature (apart from the name of the operation) that would suggest > that the reference will be leaked out of the operation's scope. It shall not leak. This is why Finalize has to unregister the object before killing it. > So the > user does this: > > declare > X : My_Concrete_Object; > begin > Register (X); > endl; > > and bang, everything breaks into pieces. Nothing breaks, X is finalized and removed from the internal list. >> You should register the object itself rather than its pointer. Use a >> constructing function which registers the object by placing it in a list or >> do an explicit call to Register. > > No way. There are many Registers and it's up to the user to decide > where the given object should be registered; constructor has no such > knowledge. He decides that upon construction: declare X : Object := Create (My_Repository); > And *when* it should be registered, which is not necessarily at > construction time. A good design rule is that all objects are usable at each point of its existence. But if unregistered object are OK, then provide a Register operation: procedure Register (X : in out Object, Y : in out Repository'Class); >> I tend to avoid "all" everywhere I can. > > Apparently here I cannot. Because you have a model in mind, which treats objects as dynamically allocated entities. This is a possible design, though it has disadvantages comparing to scoped object. But even with this design you don't necessarily need public pointers. You use handles to objects encapsulating private pointers to privately defined object types. It is more difficult to pursue in Ada because Ada lacks delegation (or, alternatively, abstract access type). Nevertheless in Ada 2005 it is quite possible. The idea is that you declare an interface type. Then you implement it in the handle object and in the private implementation object. Handle's operation implementation consists of wrappers. Interface / \ / \ Handle ---> Object Object goes into private children packages. Handle's component (pointer to class-wide) are private. It is quite boring because of the wrappers, and a combinatorial explosion upon derivation. But I deployed this schema in some projects. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de