Re: Ada-Singleton-Why does it work like this?
- From: "patrick.gunia@xxxxxxxxxxxxxx" <patrick.gunia@xxxxxxxxxxxxxx>
- Date: Wed, 25 Mar 2009 03:07:18 -0700 (PDT)
On 24 Mrz., 22:21, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
wrote:
On Tue, 24 Mar 2009 12:01:00 -0700 (PDT), patrick.gu...@xxxxxxxxxxxxxx
wrote:
I´m 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 some
module. In Ada this is achieved by putting elaboration code put in the body
of corresponding package:
package body Foo is
... -- Implementation of the entities declared in Foo
begin
... -- Elaboration code, executed once
end Foo;
A related, though a bit suspicious use of singleton is when it encapsulates
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 bind
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´m 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´t necessary in Ada this might come from the fact
that it can´t be implemented as in other languages, though using such
a construct might increase readability of the code.
.
- Follow-Ups:
- Re: Ada-Singleton-Why does it work like this?
- From: Ludovic Brenta
- Re: Ada-Singleton-Why does it work like this?
- From: Jean-Pierre Rosen
- Re: Ada-Singleton-Why does it work like this?
- From: Dmitry A. Kazakov
- Re: Ada-Singleton-Why does it work like this?
- From: patrick.gunia@xxxxxxxxxxxxxx
- Re: Ada-Singleton-Why does it work like this?
- References:
- Ada-Singleton-Why does it work like this?
- From: patrick.gunia@xxxxxxxxxxxxxx
- Re: Ada-Singleton-Why does it work like this?
- From: Dmitry A. Kazakov
- Ada-Singleton-Why does it work like this?
- Prev by Date: Re: Ada 2005 for jvm
- Next by Date: Re: Newbie Q: How to program in UTC (time/calendar) ?
- Previous by thread: Re: Ada-Singleton-Why does it work like this?
- Next by thread: Re: Ada-Singleton-Why does it work like this?
- Index(es):
Relevant Pages
|