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-Thread: 103376,b88383a5d9c51aa0 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!v39g2000yqm.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Ada-Singleton-Why does it work like this? Date: Tue, 24 Mar 2009 17:10:11 -0700 (PDT) Organization: http://groups.google.com Message-ID: <6d2b2c67-22fb-4283-87ab-58357e47d5ca@v39g2000yqm.googlegroups.com> References: <5a7a870c-40e2-4803-8753-0f9cfd2b800f@k2g2000yql.googlegroups.com> NNTP-Posting-Host: 81.151.68.6 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1237939811 30837 127.0.0.1 (25 Mar 2009 00:10:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 25 Mar 2009 00:10:11 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v39g2000yqm.googlegroups.com; posting-host=81.151.68.6; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.7) Gecko/2009021906 Firefox/3.0.7,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5243 Date: 2009-03-24T17:10:11-07:00 List-Id: On Mar 24, 8:47=A0pm, "Jeffrey R. Carter" wrote: > patrick.gu...@googlemail.com wrote: > > Hi all, > > 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. I used this code and it all worked as > > expected. My problem is, that I don=B4t ave any idea, why it does...her= e > > is my code: > > > package Singleton is > > > =A0 =A0type Singleton_Type (<>) is tagged limited private; > > =A0 =A0type Singleton_Access is access all Singleton_Type; > > > =A0 =A0function return_Single return Singleton_Access; > > > =A0 =A0procedure setValues(input : in out Singleton_Access; valueIN : > > Integer; valueIN2 : Integer); > > =A0 =A0procedure print_something(input : Singleton_Access); > > > =A0 =A0private > > =A0 =A0type Singleton_Type is tagged limited record > > =A0 =A0 =A0 =A0 =A0 =A0value : Integer; > > =A0 =A0 =A0 =A0 =A0 =A0value2 : Integer; > > =A0 =A0end record; > > > end Singleton; > > This is a very poor solution to the problem. A much simpler solution is > > package Singleton is > =A0 =A0 procedure Set (Value_1 : in Integer; Value_2 : in Integer); > > =A0 =A0 procedure Print; > end Singleton; But you can not derive a class from this: with Singletons; use Singletons; package Print_Managers is type Print_Manager is new Singleton with private; -- There should only be 1 print manager private -- implementation end Print_Managers; Now you could argue that there should just be a "package Print_Manager" and no need for a Print_Manager type... ...and the idea that you can derive from a 'Singleton' type rather defeats it as a 'pattern' but that's no bad thing IMHO! :-) Cheers -- Martin