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,54aae3da1cf935cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada Singleton Pattern Date: Thu, 16 Sep 2004 09:45:21 +0200 Message-ID: References: <%Fi1d.245967$OR2.11136154@news3.tin.it> <14p6ezf3vze8j$.j05arkr066wi.dlg@40tude.net> <87llfdgcdf.fsf@deneb.enyo.de> <1sggrr7wk1p1l$.3c2vsu0kl9qo.dlg@40tude.net> <87wtywgadq.fsf@deneb.enyo.de> <91f7q67flszs$.1qe37rlese4ui$.dlg@40tude.net> <87pt4m7lr3.fsf@deneb.enyo.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de BOlpJuibqznUPD5gETeP8QvT7cRGOCR0L+u35EX+GvqJU6lx0= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:3764 Date: 2004-09-16T09:45:21+02:00 List-Id: On Thu, 16 Sep 2004 08:48:00 +0200, Florian Weimer wrote: > * Dmitry A. Kazakov: > >> But that is unrelated to the issue of whether the scope is known. If the >> scope is known, then it is quite easy to ensure that there will be no >> dangling references to the object. Ada visibility rules ensure that. If it >> is unknown, then that is not just the singleton issue. > > How do you ensure that there's only a single instance of the singleton > if it's not declared at the library level? 8-) As long as the package is not generic, there can be only one instance of it. I mean things like: Scope : declare package Singletons is type Singleton (<>) is limited ... This_One : constant Singleton; private ... end Singletons; package body Singletons is separate; use Singletons; begin ... end Scope; Of course if somebody wishes extensible singleton types, generic singletons etc, then the scope may quickly become undefinable and the compiler will unable to check it. However, the whole idea of singleton is somehow incompatible with a possibility to extend or instantiate it! (:-)) [Ranting] Honestly, I do not believe in any need in singletons like above in Ada. We have perfect: package body Foo is ... begin -- Do here what should be done once end Foo; Examples like data base connection are rather strange. Why there should be the only one? What if I want to copy a table for Oracle to Access? For synchronization? Well, Ada has tasks and protected objects. IMO they solve the problem of mutually exclusive access in a more structured way. What have I forgot? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de