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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,54aae3da1cf935cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!newsfeed.stueberl.de!news-out.tin.it!news-in.tin.it!news4.tin.it.POSTED!not-for-mail From: Luca Stasio User-Agent: Mozilla Thunderbird 0.7.2 (Windows/20040707) X-Accept-Language: it, en, en-us MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada Singleton Pattern References: <%Fi1d.245967$OR2.11136154@news3.tin.it> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Wed, 15 Sep 2004 19:38:51 GMT NNTP-Posting-Host: 80.117.234.190 X-Complaints-To: "Please send abuse reports to abuse@tin.it and technical notifications to newsmaster@tin.it" X-Trace: news4.tin.it 1095277131 80.117.234.190 (Wed, 15 Sep 2004 21:38:51 MET DST) NNTP-Posting-Date: Wed, 15 Sep 2004 21:38:51 MET DST Organization: TIN Xref: g2news1.google.com comp.lang.ada:3756 Date: 2004-09-15T19:38:51+00:00 List-Id: Matthew Heaney ha scritto: > Luca Stasio writes: > > >>Hi, there is a way to implement the Singleton Pattern in Ada? There >>are some examples out there? Thanx. > > > I prefer to do it this way: > > package P is > pragma Elaborate_Body; > > type T (<>) is limited private; > type T_Access is access all T; > > function Object return T_Access; > > procedure Op (O : access T); > ... > private > type T is limited record ... end record; > end; > > package body P is > State : aliased T; > > function Object return T_Access is > begin > return State'Access; > end; > ... > end P; > > Technically, since there's only one object, then you don't really need > to declare the state as components of type T. T can just be a dummy > type (type T is limited null record;), and operations (like Op) can just > ignore the object passed as a parameter, and manipulate package state > directly. > > But all of this is just syntactic overhead. You can always get rid of > the type declaration, and just let the operations manipulate the package > state. (Booch calls this an "abstract state machine.") > > Of course, if this is a type hierarchy, then you probably do need a type > (since packages aren't "first class citizens," to use Wegner's phrase). > Hi... thank you too !!!