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,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!postnews.google.com!k2g2000yql.googlegroups.com!not-for-mail From: "patrick.gunia@googlemail.com" Newsgroups: comp.lang.ada Subject: Ada-Singleton-Why does it work like this? Date: Tue, 24 Mar 2009 12:01:00 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5a7a870c-40e2-4803-8753-0f9cfd2b800f@k2g2000yql.googlegroups.com> 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 1237921260 3319 127.0.0.1 (24 Mar 2009 19:01:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 24 Mar 2009 19:01:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k2g2000yql.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: g2news1.google.com comp.lang.ada:4262 Date: 2009-03-24T12:01:00-07:00 List-Id: 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...here is my code: package Singleton is type Singleton_Type (<>) is tagged limited private; type Singleton_Access is access all Singleton_Type; function return_Single return Singleton_Access; procedure setValues(input : in out Singleton_Access; valueIN : Integer; valueIN2 : Integer); procedure print_something(input : Singleton_Access); private type Singleton_Type is tagged limited record value : Integer; value2 : Integer; end record; end Singleton; Here is the implementation part: package body Singleton is It: aliased Singleton_Type; procedure setValues(input : in out Singleton_Access; valueIN : Integer; valueIN2 : Integer) is begin input.value :=3D valueIN; input.value2 :=3D valueIN2; end setValues; function return_Single return Singleton_Access is begin return It'Access; end return_Single; procedure print_something(input : Singleton_Access) is begin put(input.value); put(input.value2); end print_something; end Singleton; As far as I get it, is the declaration "type Singleton_Type (<>) is tagged limited private;" the key-feature to realize the Singleton pattern, but how, and why does this work? I looked through my Ada- book, searched the web but didn=B4t find an explanation for this construct! Could you please tell me, what exactly happens when I use (<>) within a type-declaration and why it is necessary for the Singleton-Implementation? Thanks a lot! Patrick