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



On Tue, 24 Mar 2009 12:01:00 -0700 (PDT), patrick.gunia@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. Kazakov
http://www.dmitry-kazakov.de
.



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)