Re: Ada-Singleton-Why does it work like this?



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.
.



Relevant Pages

  • Re: Ada-Singleton-Why does it work like this?
    ... Note that Ada allows you to define ... singleton arrays, tasks, and protected objects without an explicit type ... Some languages do not allow you to define an object unless it belongs to ... complicated - just that the complication ...
    (comp.lang.ada)
  • Re: Ada Singleton Pattern
    ... there is a way to implement the Singleton Pattern in Ada? ... Ada *requires* that the package initialization code runs before ...
    (comp.lang.ada)
  • Re: Ada-Singleton-Why does it work like this?
    ... through the posts of this group. ... Singleton is not needed in Ada. ... of corresponding package: ...
    (comp.lang.ada)
  • Re: Ada-Singleton-Why does it work like this?
    ... There are child packages in Ada, ... derivation. ... you may not because it is a singleton. ... package Singletons.Thread_Safe is ...
    (comp.lang.ada)
  • Re: Ada Singleton Pattern
    ... there is a way to implement the Singleton Pattern in Ada? ... :> type Singleton is limited private; ... :> type Singleton is new Integer; ... in Ada 200Y it will be possible ...
    (comp.lang.ada)