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,b88383a5d9c51aa0 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!j38g2000yqa.googlegroups.com!not-for-mail From: "patrick.gunia@googlemail.com" Newsgroups: comp.lang.ada Subject: Re: Ada-Singleton-Why does it work like this? Date: Wed, 25 Mar 2009 03:07:18 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <5a7a870c-40e2-4803-8753-0f9cfd2b800f@k2g2000yql.googlegroups.com> <13su65cm8b5ov$.1198qla32cc3i$.dlg@40tude.net> NNTP-Posting-Host: 78.34.66.221 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1237975638 15496 127.0.0.1 (25 Mar 2009 10:07:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 25 Mar 2009 10:07:18 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j38g2000yqa.googlegroups.com; posting-host=78.34.66.221; posting-account=D7TrwwoAAAAVyN71CASRiSp392RIjlsB User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.64 (Windows NT 6.0; U; de) Presto/2.1.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5253 Date: 2009-03-25T03:07:18-07:00 List-Id: On 24 Mrz., 22:21, "Dmitry A. Kazakov" wrote: > On Tue, 24 Mar 2009 12:01:00 -0700 (PDT), patrick.gu...@googlemail.com > wrote: > > > I=B4m currently working on implementing several design patterns in Ada, > > and I found some code concerning the Singleton-pattern when searching > > through the posts of this group. > > A side note. Singleton is not needed in Ada. Arguably the only valid use = of > singleton is execution of some piece of code once upon elaboration of som= e > module. In Ada this is achieved by putting elaboration code put in the bo= dy > of corresponding package: > > package body Foo is > =A0 =A0... -- Implementation of the entities declared in Foo > > begin > =A0 =A0... -- Elaboration code, executed once > end Foo; > > A related, though a bit suspicious use of singleton is when it encapsulat= es > a managed global state is achieved again by a package. See the post of > Jeffrey Carter that illustrates this case. > > The bottom lime. Singleton pattern is used only in the languages which bi= nd > visibility to type. In Ada visibility is bound directly to the module > (package), which eliminates any need in this pattern. > > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de Maybe I=B4m getting something wrong, but from my point of view, Singleton offers more possibilities than just the execution of some code on elaboration of some module.I like the dynamic version Ludovic described. It also offers the possibility to change the number of instances later on and thus increases the adaptability. When you say that Singleton isn=B4t necessary in Ada this might come from the fact that it can=B4t be implemented as in other languages, though using such a construct might increase readability of the code.