comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada Singleton Pattern
Date: Thu, 16 Sep 2004 09:45:21 +0200
Date: 2004-09-16T09:45:21+02:00	[thread overview]
Message-ID: <abs361277itw$.1u99xim20ogbn.dlg@40tude.net> (raw)
In-Reply-To: 87pt4m7lr3.fsf@deneb.enyo.de

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



  reply	other threads:[~2004-09-16  7:45 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-13 15:04 Ada Singleton Pattern Luca Stasio
2004-09-13 15:33 ` Dmitry A. Kazakov
2004-09-13 16:18   ` Luca Stasio
2004-09-13 17:01   ` Luca Stasio
2004-09-13 18:43     ` Martin Dowie
2004-09-13 19:37       ` Martin Dowie
2004-09-14  2:29       ` Steve
2004-09-14  8:52         ` Martin Dowie
2004-09-14 12:46           ` Jim Rogers
2004-09-14 13:57       ` Luca Stasio
2004-09-13 20:38     ` Georg Bauhaus
2004-09-14  8:17     ` Dmitry A. Kazakov
2004-09-14 13:56       ` Luca Stasio
2004-09-14 14:21   ` Florian Weimer
2004-09-14 14:48     ` Dmitry A. Kazakov
2004-09-14 15:04       ` Florian Weimer
2004-09-15  7:33         ` Dmitry A. Kazakov
2004-09-16  6:48           ` Florian Weimer
2004-09-16  7:45             ` Dmitry A. Kazakov [this message]
2004-09-14 15:38     ` Luca Stasio
2004-09-14 16:32       ` Florian Weimer
2004-09-14 17:43         ` Luca Stasio
2004-09-15  7:27       ` Martin Dowie
2004-09-15 19:38         ` Luca Stasio
2004-09-15  5:43 ` Matthew Heaney
2004-09-15 19:38   ` Luca Stasio
2004-09-18 21:47 ` Pylinius
2004-09-19  4:19   ` Matthew Heaney
2004-09-20  3:03     ` Pylinius
2004-09-23  7:35   ` Luca Stasio
2004-09-27  5:22     ` Pylinius
2004-09-27  8:05       ` Luca Stasio
2004-10-05 17:55       ` Luca Stasio
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox