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, T_FILL_THIS_FORM_SHORT 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!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!elnk-atl-nf1!newsfeed.earthlink.net!stamper.news.atl.earthlink.net!newsread3.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: Ada Singleton Pattern References: <%Fi1d.245967$OR2.11136154@news3.tin.it> From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 15 Sep 2004 05:43:58 GMT NNTP-Posting-Host: 64.185.133.124 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.atl.earthlink.net 1095227038 64.185.133.124 (Tue, 14 Sep 2004 22:43:58 PDT) NNTP-Posting-Date: Tue, 14 Sep 2004 22:43:58 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:3741 Date: 2004-09-15T05:43:58+00:00 List-Id: 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).