comp.lang.ada
 help / color / mirror / Atom feed
* Ada Singleton Pattern
@ 2004-09-13 15:04 Luca Stasio
  2004-09-13 15:33 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: Luca Stasio @ 2004-09-13 15:04 UTC (permalink / raw)


Hi, there is a way to implement the Singleton Pattern in Ada?
There are some examples out there?
Thanx.



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  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
                     ` (2 more replies)
  2004-09-15  5:43 ` Matthew Heaney
  2004-09-18 21:47 ` Pylinius
  2 siblings, 3 replies; 33+ messages in thread
From: Dmitry A. Kazakov @ 2004-09-13 15:33 UTC (permalink / raw)


On Mon, 13 Sep 2004 15:04:27 GMT, Luca Stasio wrote:

> Hi, there is a way to implement the Singleton Pattern in Ada?
> There are some examples out there?
> Thanx.

package Foo is
   type Singleton (<>) is limited private;
   ... -- Public interface subroutines

   The_Only_One : constant Singleton; -- The value
private
   type Singleton is new Integer; -- Any implementation you want
   The_Only_One : constant Singleton := 5;

The public view of Singleton is unconstrained and limited, which prevents
it from either being copied or declaring new objects of this type.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-13 15:33 ` Dmitry A. Kazakov
@ 2004-09-13 16:18   ` Luca Stasio
  2004-09-13 17:01   ` Luca Stasio
  2004-09-14 14:21   ` Florian Weimer
  2 siblings, 0 replies; 33+ messages in thread
From: Luca Stasio @ 2004-09-13 16:18 UTC (permalink / raw)


Dmitry A. Kazakov ha scritto:

> On Mon, 13 Sep 2004 15:04:27 GMT, Luca Stasio wrote:
> 
> 
>>Hi, there is a way to implement the Singleton Pattern in Ada?
>>There are some examples out there?
>>Thanx.
> 
> 
> package Foo is
>    type Singleton (<>) is limited private;
>    ... -- Public interface subroutines
> 
>    The_Only_One : constant Singleton; -- The value
> private
>    type Singleton is new Integer; -- Any implementation you want
>    The_Only_One : constant Singleton := 5;
> 
> The public view of Singleton is unconstrained and limited, which prevents
> it from either being copied or declaring new objects of this type.
> 
thanx a lot ;o)



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  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
                       ` (2 more replies)
  2004-09-14 14:21   ` Florian Weimer
  2 siblings, 3 replies; 33+ messages in thread
From: Luca Stasio @ 2004-09-13 17:01 UTC (permalink / raw)


Dmitry A. Kazakov ha scritto:
> On Mon, 13 Sep 2004 15:04:27 GMT, Luca Stasio wrote:
> 
> 
>>Hi, there is a way to implement the Singleton Pattern in Ada?
>>There are some examples out there?
>>Thanx.
> 
> 
> package Foo is
>    type Singleton (<>) is limited private;
>    ... -- Public interface subroutines
> 
>    The_Only_One : constant Singleton; -- The value
> private
>    type Singleton is new Integer; -- Any implementation you want
>    The_Only_One : constant Singleton := 5;
> 
> The public view of Singleton is unconstrained and limited, which prevents
> it from either being copied or declaring new objects of this type.
> 
Thanx for your answer.
Know, sorry... but, there is a way to create a Singleton Class from wich 
derive and create concrete singleton classes?
  I mean: (1) a Singleton class (2) a DatbaseAccessSingleton or a 
NetworkAccessSingleton or... heach one with its own methods but sharing 
the Singleton behaviour.

Thanx a lot for you courtesy.
Bye

----
Luca Stasio
;o)



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-13 17:01   ` Luca Stasio
@ 2004-09-13 18:43     ` Martin Dowie
  2004-09-13 19:37       ` Martin Dowie
                         ` (2 more replies)
  2004-09-13 20:38     ` Georg Bauhaus
  2004-09-14  8:17     ` Dmitry A. Kazakov
  2 siblings, 3 replies; 33+ messages in thread
From: Martin Dowie @ 2004-09-13 18:43 UTC (permalink / raw)


"Luca Stasio" <stasio2000@tin.it> wrote in message 
news:hnk1d.246585$OR2.11156430@news3.tin.it...
> Know, sorry... but, there is a way to create a Singleton Class from wich 
> derive and create concrete singleton classes?
>  I mean: (1) a Singleton class (2) a DatbaseAccessSingleton or a 
> NetworkAccessSingleton or... heach one with its own methods but sharing 
> the Singleton behaviour.

Here's one I use. It's not the complete source, which also includes 
interleavable singletons and limited singletons (also can be interleavable). 
Examples are embedded in the package spec (in an AdaBrowse format, of 
course).

I may post them on my web page if anyone is interested.

Cheers

-- Martin


--  generic_singletons.ads

-- (c) 2003, Martin M. Dowie
--
-- Instantiate a new version of this package for each type you want to be
-- a singleton.
--
-- Example
--! with Generic_Singletons;
--!
--! package My_Stuff is
--!
--! type My_Type is private;
--!
--! ...
--!
--! private
--!
--! package Root_Singleton is
--! new Generic_Singletons;
--!
--! type My_Type
--! is new Root_Singleton.Singleton with ...;
--!
--! end My_Stuff;
--!
--!
--! with My_Stuff;
--!
--! procedure Test is
--! S1 : My_Stuff.My_Type; -- Should be the one and only
--! S2 : My_Stuff.My_Type; -- Will raise Program_Error here
--! begin
--! null;
--! end Test;
pragma License (Modified_GPL);
with Ada.Finalization;
generic
   Thread_Safe : in Boolean := False;
package Generic_Singletons is
   type Singleton is tagged private;
   -- Derive your type from this type to ensure that only one instance
   -- of your type can exist within a partition <STRONG>ever</STRONG>.
   type Pointer is access all Singleton'Class;
   type Reference is access constant Singleton'Class;
private
   Number_Created : Natural := 0;
   pragma Atomic (Number_Created);
   type Singleton is
      new Ada.Finalization.Controlled with null record;
   procedure Initialize (S : in out Singleton);
   protected Semaphore is
      entry Lock;
      entry Unlock;
   private
      Is_Locked : Boolean := False;
   end Semaphore;
end Generic_Singletons;

-- generic_singletons.adb

with Ada.Exceptions; use Ada.Exceptions;
package body Generic_Singletons is
   protected body Semaphore is
      entry Lock when not Is_Locked is
      begin
         Is_Locked := True;
      end Lock;
      entry Unlock when Is_Locked is
      begin
         Is_Locked := False;
      end Unlock;
   end Semaphore;

   ----------------
   -- Initialize --
   ----------------
   procedure Initialize (S : in out Singleton) is
      pragma Warnings (Off, S);
   begin
      if Thread_Safe then
         Semaphore.Lock;
      end if;
      Number_Created := Number_Created + 1;
      if Thread_Safe then
         Semaphore.Unlock;
      end if;
      if Number_Created > 1 then
         Raise_Exception
            (Program_Error'Identity,
             "Only one instance of a Singleton is allowed at a time");
      end if;
   end Initialize;
end Generic_Singletons;





^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-13 18:43     ` Martin Dowie
@ 2004-09-13 19:37       ` Martin Dowie
  2004-09-14  2:29       ` Steve
  2004-09-14 13:57       ` Luca Stasio
  2 siblings, 0 replies; 33+ messages in thread
From: Martin Dowie @ 2004-09-13 19:37 UTC (permalink / raw)


"Martin Dowie" <martin.dowie@btopenworld.com> wrote in message 
news:ci4pok$l9u$1@titan.btinternet.com...

Just noticed this is an old copy - I think my latest is:

>   protected Semaphore is
>      entry Lock;
>      entry Unlock;
      procedure Unlock;

>      entry Unlock when Is_Locked is
       procedure Unlock is






^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-13 17:01   ` Luca Stasio
  2004-09-13 18:43     ` Martin Dowie
@ 2004-09-13 20:38     ` Georg Bauhaus
  2004-09-14  8:17     ` Dmitry A. Kazakov
  2 siblings, 0 replies; 33+ messages in thread
From: Georg Bauhaus @ 2004-09-13 20:38 UTC (permalink / raw)


Luca Stasio <stasio2000@tin.it> wrote:
: Dmitry A. Kazakov ha scritto:
:> On Mon, 13 Sep 2004 15:04:27 GMT, Luca Stasio wrote:
:> 
:> 
:>>Hi, there is a way to implement the Singleton Pattern in Ada?
:>>There are some examples out there?
:>>Thanx.
:> 
:> 
:> package Foo is
:>    type Singleton (<>) is limited private;
:>    ... -- Public interface subroutines
:> 
:>    The_Only_One : constant Singleton; -- The value
:> private
:>    type Singleton is new Integer; -- Any implementation you want
:>    The_Only_One : constant Singleton := 5;
:> 
:> The public view of Singleton is unconstrained and limited, which prevents
:> it from either being copied or declaring new objects of this type.
:> 
: Thanx for your answer.
: Know, sorry... but, there is a way to create a Singleton Class from wich 
: derive and create concrete singleton classes?
:  I mean: (1) a Singleton class (2) a DatbaseAccessSingleton or a 
: NetworkAccessSingleton or... heach one with its own methods but sharing 
: the Singleton behaviour.
: 

The following outlines a solution; in Ada 200Y it will be possible
to have initialised constants of a limited type, which might help,
the experts might tell you.
In the following, the constant is replaced with a function returning
the very same singleton.


with DB;  --  database stuff

package Single is

   pragma Elaborate_Body;

   type Singleton(<>) is tagged limited private;

    -- (this should be moved to another package: )
   type The_One_And_Only_DB is new Singleton with private;

   function DB17 return The_One_And_Only_DB;
    --  the database singleton

private
   type Singleton is tagged limited null record;

   type The_One_And_Only_DB is new Singleton with record
      Comp: DB.Stuff := DB.init;
      -- note that you can pass The_One_And_Only'Access to DB.init
      -- ...
   end record;

end Single;


package body Single is

   It: The_One_And_Only_DB;
    --  with default initialisation, values provided by DB.init

   function DB17 return The_One_And_Only_DB is
   begin
      return It;
   end DB17;

end Single;


-- Georg



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  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 13:57       ` Luca Stasio
  2 siblings, 1 reply; 33+ messages in thread
From: Steve @ 2004-09-14  2:29 UTC (permalink / raw)


Isn't it kind of silly to build a semaphore using a protected object?

Why not:
   protected SingleGet is
      procedure Get( ok : out Boolean );
   private
      Is_First : Boolean := TRUE;
   end SingleGet;

   protected body SingleGet is
      procedure Get( ok : out Boolean ) do
      begin
        ok := Is_First;
        Is_First := FALSE;
      end Get;
   end SingleGet;

And then in Initialize:

      if Thread_Safe then
         SingleGet.Get( ok );
      else
        Number_Created := Number_Created + 1;
        gotIt := Number_Created = 1;
      end if;
      if not ok then
        Raise_Exception
           (Program_Error'Identity,
            "Only one instance of a Singleton is allowed at a time");
      end if;

Although it's unclear why a counter is used.

I started programming real-time muti-tasking systems using semaphores,
events, etc.  When I first started using Ada, I created semaphores using a
protected type and built the little houses of cards I was accustomed to.
Eventually I learned that there was a reason for having something other than
semaphores and events.  If you use them correctly you'll find you eliminate
problems of having semaphores that never get released, etc.

Steve
(The Duck)

"Martin Dowie" <martin.dowie@btopenworld.com> wrote in message
news:ci4pok$l9u$1@titan.btinternet.com...
> "Luca Stasio" <stasio2000@tin.it> wrote in message
> news:hnk1d.246585$OR2.11156430@news3.tin.it...
> > Know, sorry... but, there is a way to create a Singleton Class from wich
> > derive and create concrete singleton classes?
> >  I mean: (1) a Singleton class (2) a DatbaseAccessSingleton or a
> > NetworkAccessSingleton or... heach one with its own methods but sharing
> > the Singleton behaviour.
>
> Here's one I use. It's not the complete source, which also includes
> interleavable singletons and limited singletons (also can be
interleavable).
> Examples are embedded in the package spec (in an AdaBrowse format, of
> course).
>
> I may post them on my web page if anyone is interested.
>
> Cheers
>
> -- Martin
>
>
> --  generic_singletons.ads
>
> -- (c) 2003, Martin M. Dowie
> --
> -- Instantiate a new version of this package for each type you want to be
> -- a singleton.
> --
> -- Example
> --! with Generic_Singletons;
> --!
> --! package My_Stuff is
> --!
> --! type My_Type is private;
> --!
> --! ...
> --!
> --! private
> --!
> --! package Root_Singleton is
> --! new Generic_Singletons;
> --!
> --! type My_Type
> --! is new Root_Singleton.Singleton with ...;
> --!
> --! end My_Stuff;
> --!
> --!
> --! with My_Stuff;
> --!
> --! procedure Test is
> --! S1 : My_Stuff.My_Type; -- Should be the one and only
> --! S2 : My_Stuff.My_Type; -- Will raise Program_Error here
> --! begin
> --! null;
> --! end Test;
> pragma License (Modified_GPL);
> with Ada.Finalization;
> generic
>    Thread_Safe : in Boolean := False;
> package Generic_Singletons is
>    type Singleton is tagged private;
>    -- Derive your type from this type to ensure that only one instance
>    -- of your type can exist within a partition <STRONG>ever</STRONG>.
>    type Pointer is access all Singleton'Class;
>    type Reference is access constant Singleton'Class;
> private
>    Number_Created : Natural := 0;
>    pragma Atomic (Number_Created);
>    type Singleton is
>       new Ada.Finalization.Controlled with null record;
>    procedure Initialize (S : in out Singleton);
>    protected Semaphore is
>       entry Lock;
>       entry Unlock;
>    private
>       Is_Locked : Boolean := False;
>    end Semaphore;
> end Generic_Singletons;
>
> -- generic_singletons.adb
>
> with Ada.Exceptions; use Ada.Exceptions;
> package body Generic_Singletons is
>    protected body Semaphore is
>       entry Lock when not Is_Locked is
>       begin
>          Is_Locked := True;
>       end Lock;
>       entry Unlock when Is_Locked is
>       begin
>          Is_Locked := False;
>       end Unlock;
>    end Semaphore;
>
>    ----------------
>    -- Initialize --
>    ----------------
>    procedure Initialize (S : in out Singleton) is
>       pragma Warnings (Off, S);
>    begin
>       if Thread_Safe then
>          Semaphore.Lock;
>       end if;
>       Number_Created := Number_Created + 1;
>       if Thread_Safe then
>          Semaphore.Unlock;
>       end if;
>       if Number_Created > 1 then
>          Raise_Exception
>             (Program_Error'Identity,
>              "Only one instance of a Singleton is allowed at a time");
>       end if;
>    end Initialize;
> end Generic_Singletons;
>
>





^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-13 17:01   ` Luca Stasio
  2004-09-13 18:43     ` Martin Dowie
  2004-09-13 20:38     ` Georg Bauhaus
@ 2004-09-14  8:17     ` Dmitry A. Kazakov
  2004-09-14 13:56       ` Luca Stasio
  2 siblings, 1 reply; 33+ messages in thread
From: Dmitry A. Kazakov @ 2004-09-14  8:17 UTC (permalink / raw)


On Mon, 13 Sep 2004 17:01:01 GMT, Luca Stasio wrote:

> Dmitry A. Kazakov ha scritto:
>> On Mon, 13 Sep 2004 15:04:27 GMT, Luca Stasio wrote:
>> 
>>>Hi, there is a way to implement the Singleton Pattern in Ada?
>>>There are some examples out there?
>>>Thanx.
>> 
>> package Foo is
>>    type Singleton (<>) is limited private;
>>    ... -- Public interface subroutines
>> 
>>    The_Only_One : constant Singleton; -- The value
>> private
>>    type Singleton is new Integer; -- Any implementation you want
>>    The_Only_One : constant Singleton := 5;
>> 
>> The public view of Singleton is unconstrained and limited, which prevents
>> it from either being copied or declaring new objects of this type.
>> 
> Thanx for your answer.
> Know, sorry... but, there is a way to create a Singleton Class from wich 
> derive and create concrete singleton classes?

"(<>) is limited" is a kind of such class built in the language. It can be
specified as a generic formal parameter for example. So formally you do not
need to create it, it is already here. However, if you want singleton types
to share something common, apart from being just singletons, then you can
create an abstract type:

with Ada.Finalization;
package Singletons is
   type Singleton (<>) is abstract tagged limited private;
   -- This is an extensible type. Interface follows, it should
   -- have only in-methods, because Singleton is viewed as
   -- a constant. Looks nasty, but technically it is no problem,
   -- because the implementation may use a function returning
   -- the object so that the methods could access the object
   -- directly.
   function Get_Name (X : Singleton) return String is abstract;
   ...
private
   type Singleton is abstract
      new Ada.Finalization.Limited_Controlled with null record;
end Singletons;

Note that the base Limited_Controlled is hidden. It means that only the
packages having a private view on Singleton can in effect extend it. Though
others will be able to declare an extension type, they will fail to create
any concrete object of that type.
  
>   I mean: (1) a Singleton class (2) a DatbaseAccessSingleton or a 
> NetworkAccessSingleton or... heach one with its own methods but sharing 
> the Singleton behaviour.

package Singletons.DB is
   type DB_Singleton is new Singleton with private;
   -- Implementation of the interface, overriding all abstracts:
   function Get_Name (X : DB_Singleton) return String;
   ...
   -- The singleton object itself. Alas, it cannot be declared as a
   -- variable, because the object is unconstrained in its public
   -- view, but you can declare it as either a constant or a function.
   -- For clients it will make no difference:
   DB : constant DB_Singleton;
   -- Or else   
   function DB return DB_Singleton;
private
   DB : constant DB_Singleton; -- If declared as a constant

   type DB_Singleton is new Singleton with
   record
      ...
   end record;
   procedure Finalize (X : in out DB_Singleton);
   procedure Initialize (X : in out DB_Singleton);
end Singletons.DB;

When DB is a function then in the body:

package Singletons.DB is
   procedure Finalize (X : in out DB_Singleton) is
   begin
      ...
   end Finalize;
   procedure Initialize (X : in out DB_Singleton) is
   begin
      ...
   end Initialize;

   My_DB : DB_Singleton;

   function DB return DB_Singleton is
   begin
      return My_DB;
      -- Non-local limited objects can be returned
      -- by reference
   end DB;
   ...

As for singletons in the sense of objects exclusively used by a scheduled
item, see what other posters already wrote. You can use a mutex protected
object or a task implementing a monitor and mix in to the singleton object
trough an access discriminant.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-14  2:29       ` Steve
@ 2004-09-14  8:52         ` Martin Dowie
  2004-09-14 12:46           ` Jim Rogers
  0 siblings, 1 reply; 33+ messages in thread
From: Martin Dowie @ 2004-09-14  8:52 UTC (permalink / raw)


Steve wrote:
> Isn't it kind of silly to build a semaphore using a protected object?

There wasn't any real reason for doing it this way other than it is clear
(for a 2 subprogram package). I totally agree with you though and perhaps I
might just go and change it now... :-)

Anyone for Ada.Patterns.* in Ada1Z? :-)







^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-14  8:52         ` Martin Dowie
@ 2004-09-14 12:46           ` Jim Rogers
  0 siblings, 0 replies; 33+ messages in thread
From: Jim Rogers @ 2004-09-14 12:46 UTC (permalink / raw)


"Martin Dowie" <martin.dowie@baesystems.com> wrote in
news:4146af4e$1_1@baen1673807.greenlnk.net: 

> 
> Anyone for Ada.Patterns.* in Ada1Z? :-)
> 

I have a start on some of those patterns at
http://home.att.net/~jimmaureenrogers/
look for the link labeled "shared resource design patterns".

Jim Rogers




^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-14  8:17     ` Dmitry A. Kazakov
@ 2004-09-14 13:56       ` Luca Stasio
  0 siblings, 0 replies; 33+ messages in thread
From: Luca Stasio @ 2004-09-14 13:56 UTC (permalink / raw)


Dmitry A. Kazakov wrote:
> On Mon, 13 Sep 2004 17:01:01 GMT, Luca Stasio wrote:
> 
> 
>>Dmitry A. Kazakov ha scritto:
>>
>>>On Mon, 13 Sep 2004 15:04:27 GMT, Luca Stasio wrote:
>>>
>>>
>>>>Hi, there is a way to implement the Singleton Pattern in Ada?
>>>>There are some examples out there?
>>>>Thanx.
>>>
>>>package Foo is
>>>   type Singleton (<>) is limited private;
>>>   ... -- Public interface subroutines
>>>
>>>   The_Only_One : constant Singleton; -- The value
>>>private
>>>   type Singleton is new Integer; -- Any implementation you want
>>>   The_Only_One : constant Singleton := 5;
>>>
>>>The public view of Singleton is unconstrained and limited, which prevents
>>>it from either being copied or declaring new objects of this type.
>>>
>>
>>Thanx for your answer.
>>Know, sorry... but, there is a way to create a Singleton Class from wich 
>>derive and create concrete singleton classes?
> 
> 
> "(<>) is limited" is a kind of such class built in the language. It can be
> specified as a generic formal parameter for example. So formally you do not
> need to create it, it is already here. However, if you want singleton types
> to share something common, apart from being just singletons, then you can
> create an abstract type:
> 
> with Ada.Finalization;
> package Singletons is
>    type Singleton (<>) is abstract tagged limited private;
>    -- This is an extensible type. Interface follows, it should
>    -- have only in-methods, because Singleton is viewed as
>    -- a constant. Looks nasty, but technically it is no problem,
>    -- because the implementation may use a function returning
>    -- the object so that the methods could access the object
>    -- directly.
>    function Get_Name (X : Singleton) return String is abstract;
>    ...
> private
>    type Singleton is abstract
>       new Ada.Finalization.Limited_Controlled with null record;
> end Singletons;
> 
> Note that the base Limited_Controlled is hidden. It means that only the
> packages having a private view on Singleton can in effect extend it. Though
> others will be able to declare an extension type, they will fail to create
> any concrete object of that type.
>   
> 
>>  I mean: (1) a Singleton class (2) a DatbaseAccessSingleton or a 
>>NetworkAccessSingleton or... heach one with its own methods but sharing 
>>the Singleton behaviour.
> 
> 
> package Singletons.DB is
>    type DB_Singleton is new Singleton with private;
>    -- Implementation of the interface, overriding all abstracts:
>    function Get_Name (X : DB_Singleton) return String;
>    ...
>    -- The singleton object itself. Alas, it cannot be declared as a
>    -- variable, because the object is unconstrained in its public
>    -- view, but you can declare it as either a constant or a function.
>    -- For clients it will make no difference:
>    DB : constant DB_Singleton;
>    -- Or else   
>    function DB return DB_Singleton;
> private
>    DB : constant DB_Singleton; -- If declared as a constant
> 
>    type DB_Singleton is new Singleton with
>    record
>       ...
>    end record;
>    procedure Finalize (X : in out DB_Singleton);
>    procedure Initialize (X : in out DB_Singleton);
> end Singletons.DB;
> 
> When DB is a function then in the body:
> 
> package Singletons.DB is
>    procedure Finalize (X : in out DB_Singleton) is
>    begin
>       ...
>    end Finalize;
>    procedure Initialize (X : in out DB_Singleton) is
>    begin
>       ...
>    end Initialize;
> 
>    My_DB : DB_Singleton;
> 
>    function DB return DB_Singleton is
>    begin
>       return My_DB;
>       -- Non-local limited objects can be returned
>       -- by reference
>    end DB;
>    ...
> 
> As for singletons in the sense of objects exclusively used by a scheduled
> item, see what other posters already wrote. You can use a mutex protected
> object or a task implementing a monitor and mix in to the singleton object
> trough an access discriminant.
> 
Really thank you all



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-13 18:43     ` Martin Dowie
  2004-09-13 19:37       ` Martin Dowie
  2004-09-14  2:29       ` Steve
@ 2004-09-14 13:57       ` Luca Stasio
  2 siblings, 0 replies; 33+ messages in thread
From: Luca Stasio @ 2004-09-14 13:57 UTC (permalink / raw)


Martin Dowie wrote:
> "Luca Stasio" <stasio2000@tin.it> wrote in message 
> news:hnk1d.246585$OR2.11156430@news3.tin.it...
> 
>>Know, sorry... but, there is a way to create a Singleton Class from wich 
>>derive and create concrete singleton classes?
>> I mean: (1) a Singleton class (2) a DatbaseAccessSingleton or a 
>>NetworkAccessSingleton or... heach one with its own methods but sharing 
>>the Singleton behaviour.
> 
> 
> Here's one I use. It's not the complete source, which also includes 
> interleavable singletons and limited singletons (also can be interleavable). 
> Examples are embedded in the package spec (in an AdaBrowse format, of 
> course).
> 
> I may post them on my web page if anyone is interested.
> 
> Cheers
> 
> -- Martin
> 
> 
> --  generic_singletons.ads
> 
> -- (c) 2003, Martin M. Dowie
> --
> -- Instantiate a new version of this package for each type you want to be
> -- a singleton.
> --
> -- Example
> --! with Generic_Singletons;
> --!
> --! package My_Stuff is
> --!
> --! type My_Type is private;
> --!
> --! ...
> --!
> --! private
> --!
> --! package Root_Singleton is
> --! new Generic_Singletons;
> --!
> --! type My_Type
> --! is new Root_Singleton.Singleton with ...;
> --!
> --! end My_Stuff;
> --!
> --!
> --! with My_Stuff;
> --!
> --! procedure Test is
> --! S1 : My_Stuff.My_Type; -- Should be the one and only
> --! S2 : My_Stuff.My_Type; -- Will raise Program_Error here
> --! begin
> --! null;
> --! end Test;
> pragma License (Modified_GPL);
> with Ada.Finalization;
> generic
>    Thread_Safe : in Boolean := False;
> package Generic_Singletons is
>    type Singleton is tagged private;
>    -- Derive your type from this type to ensure that only one instance
>    -- of your type can exist within a partition <STRONG>ever</STRONG>.
>    type Pointer is access all Singleton'Class;
>    type Reference is access constant Singleton'Class;
> private
>    Number_Created : Natural := 0;
>    pragma Atomic (Number_Created);
>    type Singleton is
>       new Ada.Finalization.Controlled with null record;
>    procedure Initialize (S : in out Singleton);
>    protected Semaphore is
>       entry Lock;
>       entry Unlock;
>    private
>       Is_Locked : Boolean := False;
>    end Semaphore;
> end Generic_Singletons;
> 
> -- generic_singletons.adb
> 
> with Ada.Exceptions; use Ada.Exceptions;
> package body Generic_Singletons is
>    protected body Semaphore is
>       entry Lock when not Is_Locked is
>       begin
>          Is_Locked := True;
>       end Lock;
>       entry Unlock when Is_Locked is
>       begin
>          Is_Locked := False;
>       end Unlock;
>    end Semaphore;
> 
>    ----------------
>    -- Initialize --
>    ----------------
>    procedure Initialize (S : in out Singleton) is
>       pragma Warnings (Off, S);
>    begin
>       if Thread_Safe then
>          Semaphore.Lock;
>       end if;
>       Number_Created := Number_Created + 1;
>       if Thread_Safe then
>          Semaphore.Unlock;
>       end if;
>       if Number_Created > 1 then
>          Raise_Exception
>             (Program_Error'Identity,
>              "Only one instance of a Singleton is allowed at a time");
>       end if;
>    end Initialize;
> end Generic_Singletons;
> 
> 
Thanx a lot



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-13 15:33 ` Dmitry A. Kazakov
  2004-09-13 16:18   ` Luca Stasio
  2004-09-13 17:01   ` Luca Stasio
@ 2004-09-14 14:21   ` Florian Weimer
  2004-09-14 14:48     ` Dmitry A. Kazakov
  2004-09-14 15:38     ` Luca Stasio
  2 siblings, 2 replies; 33+ messages in thread
From: Florian Weimer @ 2004-09-14 14:21 UTC (permalink / raw)


* Dmitry A. Kazakov:

> On Mon, 13 Sep 2004 15:04:27 GMT, Luca Stasio wrote:
>
>> Hi, there is a way to implement the Singleton Pattern in Ada?
>> There are some examples out there?
>> Thanx.
>
> package Foo is
>    type Singleton (<>) is limited private;
>    ... -- Public interface subroutines
>
>    The_Only_One : constant Singleton; -- The value
> private
>    type Singleton is new Integer; -- Any implementation you want
>    The_Only_One : constant Singleton := 5;
>
> The public view of Singleton is unconstrained and limited, which prevents
> it from either being copied or declaring new objects of this type.

This is only a partial solution, unfortunately.

Ada *requires* that the package initialization code runs before
The_Only_One is accessed.  This is different from many other languages
(where the initialization order of global objects is mostly
unspecified and not related to actual usage patterns) and solves a big
chunk of the singleton problem.

However, you still have to deal with termination on your own: you must
ensure that no client is still using the singleton object before you
destroy it.  There is no direct support in the language for this part
of the problem, and you have to use one of the traditional approaches
if this matters to your application (or assignment 8-).

(I tried to avoid Ada-specific terminology above because Luca probably
isn't familiar with the Ada language.)



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-14 14:21   ` Florian Weimer
@ 2004-09-14 14:48     ` Dmitry A. Kazakov
  2004-09-14 15:04       ` Florian Weimer
  2004-09-14 15:38     ` Luca Stasio
  1 sibling, 1 reply; 33+ messages in thread
From: Dmitry A. Kazakov @ 2004-09-14 14:48 UTC (permalink / raw)


On Tue, 14 Sep 2004 16:21:16 +0200, Florian Weimer wrote:

> * Dmitry A. Kazakov:
> 
>> On Mon, 13 Sep 2004 15:04:27 GMT, Luca Stasio wrote:
>>
>>> Hi, there is a way to implement the Singleton Pattern in Ada?
>>> There are some examples out there?
>>> Thanx.
>>
>> package Foo is
>>    type Singleton (<>) is limited private;
>>    ... -- Public interface subroutines
>>
>>    The_Only_One : constant Singleton; -- The value
>> private
>>    type Singleton is new Integer; -- Any implementation you want
>>    The_Only_One : constant Singleton := 5;
>>
>> The public view of Singleton is unconstrained and limited, which prevents
>> it from either being copied or declaring new objects of this type.
> 
> This is only a partial solution, unfortunately.

Yes.

> Ada *requires* that the package initialization code runs before
> The_Only_One is accessed.  This is different from many other languages
> (where the initialization order of global objects is mostly
> unspecified and not related to actual usage patterns) and solves a big
> chunk of the singleton problem.
> 
> However, you still have to deal with termination on your own: you must
> ensure that no client is still using the singleton object before you
> destroy it.  There is no direct support in the language for this part
> of the problem, and you have to use one of the traditional approaches
> if this matters to your application (or assignment 8-).

Only if the scope of the singleton is unknown, and so need to be dynamic.
But it is not the case for the example given. The scope of the singleton is
one of the package. The package itself can be nested (not to be at the
library level). So clients are prevented from accessing it after its
finalization by the compiler.

[Another problem with the pattern above is the construction parameters,
when unknown. Otherwise, The_Only_One can be made a function and the object
be constructed within the package body after begin ... end Foo. I believe
that Ada 2005 will fix that by allowing Pickwickian assignments of limited
objects. (:-))]

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-14 14:48     ` Dmitry A. Kazakov
@ 2004-09-14 15:04       ` Florian Weimer
  2004-09-15  7:33         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 33+ messages in thread
From: Florian Weimer @ 2004-09-14 15:04 UTC (permalink / raw)


* Dmitry A. Kazakov:

> Only if the scope of the singleton is unknown, and so need to be dynamic.
> But it is not the case for the example given. The scope of the singleton is
> one of the package. The package itself can be nested (not to be at the
> library level). So clients are prevented from accessing it after its
> finalization by the compiler.

Oh, come on, you should be able to abstract a bit from the concrete
code you gave. 8-) Often, singletons are used to manage external
resources, and some cleanup operation is required.



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-14 14:21   ` Florian Weimer
  2004-09-14 14:48     ` Dmitry A. Kazakov
@ 2004-09-14 15:38     ` Luca Stasio
  2004-09-14 16:32       ` Florian Weimer
  2004-09-15  7:27       ` Martin Dowie
  1 sibling, 2 replies; 33+ messages in thread
From: Luca Stasio @ 2004-09-14 15:38 UTC (permalink / raw)


Florian Weimer ha scritto:
> * Dmitry A. Kazakov:
> 
> 
>>On Mon, 13 Sep 2004 15:04:27 GMT, Luca Stasio wrote:
>>
>>
>>>Hi, there is a way to implement the Singleton Pattern in Ada?
>>>There are some examples out there?
>>>Thanx.
>>
>>package Foo is
>>   type Singleton (<>) is limited private;
>>   ... -- Public interface subroutines
>>
>>   The_Only_One : constant Singleton; -- The value
>>private
>>   type Singleton is new Integer; -- Any implementation you want
>>   The_Only_One : constant Singleton := 5;
>>
>>The public view of Singleton is unconstrained and limited, which prevents
>>it from either being copied or declaring new objects of this type.
> 
> 
> This is only a partial solution, unfortunately.
> 
> Ada *requires* that the package initialization code runs before
> The_Only_One is accessed.  This is different from many other languages
> (where the initialization order of global objects is mostly
> unspecified and not related to actual usage patterns) and solves a big
> chunk of the singleton problem.
> 
> However, you still have to deal with termination on your own: you must
> ensure that no client is still using the singleton object before you
> destroy it.  There is no direct support in the language for this part
> of the problem, and you have to use one of the traditional approaches
> if this matters to your application (or assignment 8-).
> 
> (I tried to avoid Ada-specific terminology above because Luca probably
> isn't familiar with the Ada language.)

Hi, is the one from Martin Dowie and Steve a right solution?
Thanx a lot.

Luca Stasio



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  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
  1 sibling, 1 reply; 33+ messages in thread
From: Florian Weimer @ 2004-09-14 16:32 UTC (permalink / raw)


* Luca Stasio:

> Hi, is the one from Martin Dowie and Steve a right solution?

There is no "right" solution because the problem is quite complex.



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-14 16:32       ` Florian Weimer
@ 2004-09-14 17:43         ` Luca Stasio
  0 siblings, 0 replies; 33+ messages in thread
From: Luca Stasio @ 2004-09-14 17:43 UTC (permalink / raw)


Florian Weimer ha scritto:

> * Luca Stasio:
> 
> 
>>Hi, is the one from Martin Dowie and Steve a right solution?
> 
> 
> There is no "right" solution because the problem is quite complex.
I know... sorry, with right you may intend "possible"... I know that 
this problem is quite complicated. You'r right!!!!



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-13 15:04 Ada Singleton Pattern Luca Stasio
  2004-09-13 15:33 ` Dmitry A. Kazakov
@ 2004-09-15  5:43 ` Matthew Heaney
  2004-09-15 19:38   ` Luca Stasio
  2004-09-18 21:47 ` Pylinius
  2 siblings, 1 reply; 33+ messages in thread
From: Matthew Heaney @ 2004-09-15  5:43 UTC (permalink / raw)


Luca Stasio <stasio2000@tin.it> writes:

> Hi, there is a way to implement the Singleton Pattern in Ada?  There
> are some examples out there?  Thanx.

I prefer to do it this way:

package P is
   pragma Elaborate_Body;

   type T (<>) is limited private;
   type T_Access is access all T;

   function Object return T_Access;

   procedure Op (O : access T);
   ...
private
   type T is limited record ... end record;
end;

package body P is
   State : aliased T;

   function Object return T_Access is
   begin
      return State'Access;
   end;
   ...
end P;

Technically, since there's only one object, then you don't really need
to declare the state as components of type T.  T can just be a dummy
type (type T is limited null record;), and operations (like Op) can just
ignore the object passed as a parameter, and manipulate package state
directly.

But all of this is just syntactic overhead.  You can always get rid of
the type declaration, and just let the operations manipulate the package
state.  (Booch calls this an "abstract state machine.")

Of course, if this is a type hierarchy, then you probably do need a type
(since packages aren't "first class citizens," to use Wegner's phrase).




^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-14 15:38     ` Luca Stasio
  2004-09-14 16:32       ` Florian Weimer
@ 2004-09-15  7:27       ` Martin Dowie
  2004-09-15 19:38         ` Luca Stasio
  1 sibling, 1 reply; 33+ messages in thread
From: Martin Dowie @ 2004-09-15  7:27 UTC (permalink / raw)


Luca Stasio wrote:

> Hi, is the one from Martin Dowie and Steve a right solution?

Both are "right" in that they offer the solution you require (an OO
singleton). The difference in is in implementation. While the code I gave
you works, I'd agree with Steve that there is a "more Ada-way" of
implementing it. But you can use the code I sent 'as is' without any
problems.

-- Martin





^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-14 15:04       ` Florian Weimer
@ 2004-09-15  7:33         ` Dmitry A. Kazakov
  2004-09-16  6:48           ` Florian Weimer
  0 siblings, 1 reply; 33+ messages in thread
From: Dmitry A. Kazakov @ 2004-09-15  7:33 UTC (permalink / raw)


On Tue, 14 Sep 2004 17:04:17 +0200, Florian Weimer wrote:

> * Dmitry A. Kazakov:
> 
>> Only if the scope of the singleton is unknown, and so need to be dynamic.
>> But it is not the case for the example given. The scope of the singleton is
>> one of the package. The package itself can be nested (not to be at the
>> library level). So clients are prevented from accessing it after its
>> finalization by the compiler.
> 
> Oh, come on, you should be able to abstract a bit from the concrete
> code you gave. 8-) Often, singletons are used to manage external
> resources, and some cleanup operation is required.

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. It is rather about
pointers, smart pointers, handles, garbage collection etc. From the
original post it is unclear what is actually needed. So I'd stick to my
trivial case for a while. (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-15  7:27       ` Martin Dowie
@ 2004-09-15 19:38         ` Luca Stasio
  0 siblings, 0 replies; 33+ messages in thread
From: Luca Stasio @ 2004-09-15 19:38 UTC (permalink / raw)


Martin Dowie ha scritto:
> Luca Stasio wrote:
> 
> 
>>Hi, is the one from Martin Dowie and Steve a right solution?
> 
> 
> Both are "right" in that they offer the solution you require (an OO
> singleton). The difference in is in implementation. While the code I gave
> you works, I'd agree with Steve that there is a "more Ada-way" of
> implementing it. But you can use the code I sent 'as is' without any
> problems.
> 
> -- Martin
> 
> 

As I think... thanx a lot !!!



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-15  5:43 ` Matthew Heaney
@ 2004-09-15 19:38   ` Luca Stasio
  0 siblings, 0 replies; 33+ messages in thread
From: Luca Stasio @ 2004-09-15 19:38 UTC (permalink / raw)


Matthew Heaney ha scritto:

> Luca Stasio <stasio2000@tin.it> writes:
> 
> 
>>Hi, there is a way to implement the Singleton Pattern in Ada?  There
>>are some examples out there?  Thanx.
> 
> 
> I prefer to do it this way:
> 
> package P is
>    pragma Elaborate_Body;
> 
>    type T (<>) is limited private;
>    type T_Access is access all T;
> 
>    function Object return T_Access;
> 
>    procedure Op (O : access T);
>    ...
> private
>    type T is limited record ... end record;
> end;
> 
> package body P is
>    State : aliased T;
> 
>    function Object return T_Access is
>    begin
>       return State'Access;
>    end;
>    ...
> end P;
> 
> Technically, since there's only one object, then you don't really need
> to declare the state as components of type T.  T can just be a dummy
> type (type T is limited null record;), and operations (like Op) can just
> ignore the object passed as a parameter, and manipulate package state
> directly.
> 
> But all of this is just syntactic overhead.  You can always get rid of
> the type declaration, and just let the operations manipulate the package
> state.  (Booch calls this an "abstract state machine.")
> 
> Of course, if this is a type hierarchy, then you probably do need a type
> (since packages aren't "first class citizens," to use Wegner's phrase).
> 

Hi... thank you too !!!



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-15  7:33         ` Dmitry A. Kazakov
@ 2004-09-16  6:48           ` Florian Weimer
  2004-09-16  7:45             ` Dmitry A. Kazakov
  0 siblings, 1 reply; 33+ messages in thread
From: Florian Weimer @ 2004-09-16  6:48 UTC (permalink / raw)


* 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-)

> It is rather about pointers, smart pointers, handles, garbage
> collection etc.

Indeed, some think that these have to be part of a singleton that
deals with destruction and not just construction.



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-16  6:48           ` Florian Weimer
@ 2004-09-16  7:45             ` Dmitry A. Kazakov
  0 siblings, 0 replies; 33+ messages in thread
From: Dmitry A. Kazakov @ 2004-09-16  7:45 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-13 15:04 Ada Singleton Pattern Luca Stasio
  2004-09-13 15:33 ` Dmitry A. Kazakov
  2004-09-15  5:43 ` Matthew Heaney
@ 2004-09-18 21:47 ` Pylinius
  2004-09-19  4:19   ` Matthew Heaney
  2004-09-23  7:35   ` Luca Stasio
  2 siblings, 2 replies; 33+ messages in thread
From: Pylinius @ 2004-09-18 21:47 UTC (permalink / raw)


Luca Stasio wrote:
> Hi, there is a way to implement the Singleton Pattern in Ada?
> There are some examples out there?
> Thanx.

package Example_Of_Singleton is

    procedure Do_Something;

    procedure Do_Something_Else;

end;


Bring it on you stupid GangOfFour bastards, with your idiotic bloated
idioms that inculcate and contaminate perfectly good alternative
languages!

Bring.

It.

On.




^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  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
  1 sibling, 1 reply; 33+ messages in thread
From: Matthew Heaney @ 2004-09-19  4:19 UTC (permalink / raw)


Pylinius <p@y.com> wrote in message news:<414CAC2B.60400@y.com>...
> Luca Stasio wrote:
> > Hi, there is a way to implement the Singleton Pattern in Ada?
> > There are some examples out there?
> > Thanx.
> 
> package Example_Of_Singleton is
> 
>     procedure Do_Something;
> 
>     procedure Do_Something_Else;
> 
> end;
> 
> 
> Bring it on you stupid GangOfFour bastards, with your idiotic bloated
> idioms that inculcate and contaminate perfectly good alternative
> languages!


I alluded to this in my previous post.  To be fair, though, you can do
this in C++ too:

namespace Example_Of_Singleton
{
   void do_something();
   void do_something_else();
}

One advantage of using a type is if the type is tagged.  If there's a
singleton instance of type in the class, then you can use that as a
value of an object whose type is class-wide.

However, most of the time you don't need all of this infrastructure,
and the package/namespace technique is perfectly adequate.

-Matt



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-19  4:19   ` Matthew Heaney
@ 2004-09-20  3:03     ` Pylinius
  0 siblings, 0 replies; 33+ messages in thread
From: Pylinius @ 2004-09-20  3:03 UTC (permalink / raw)


Matthew Heaney wrote:
> Pylinius <p@y.com> wrote in message news:<414CAC2B.60400@y.com>...
> 
>>Luca Stasio wrote:
>>
>>>Hi, there is a way to implement the Singleton Pattern in Ada?
>>>There are some examples out there?
>>>Thanx.
>>>
>>package Example_Of_Singleton is
>>
>>    procedure Do_Something;
>>
>>    procedure Do_Something_Else;
>>
>>end;
>>
>>
>>Bring it on you stupid GangOfFour bastards, with your idiotic bloated
>>idioms that inculcate and contaminate perfectly good alternative
>>languages!
>>
> 
> 
> I alluded to this in my previous post.  To be fair, though, you can do
> this in C++ too:
> 
> namespace Example_Of_Singleton
> {
>    void do_something();
>    void do_something_else();
> }
> 
> One advantage of using a type is if the type is tagged.  If there's a
> singleton instance of type in the class, then you can use that as a
> value of an object whose type is class-wide.
> 
> However, most of the time you don't need all of this infrastructure,
> and the package/namespace technique is perfectly adequate.
> 
> -Matt
> 

Thank you, and thanks for Charles, which essentially
achieves the capabilities that the Ada gods intended
without being a whore to the mindless C++/Java mindset.






^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-18 21:47 ` Pylinius
  2004-09-19  4:19   ` Matthew Heaney
@ 2004-09-23  7:35   ` Luca Stasio
  2004-09-27  5:22     ` Pylinius
  1 sibling, 1 reply; 33+ messages in thread
From: Luca Stasio @ 2004-09-23  7:35 UTC (permalink / raw)


Pylinius ha scritto:
> Luca Stasio wrote:
> 
>> Hi, there is a way to implement the Singleton Pattern in Ada?
>> There are some examples out there?
>> Thanx.
> 
> 
> package Example_Of_Singleton is
> 
>    procedure Do_Something;
> 
>    procedure Do_Something_Else;
> 
> end;
> 
> 
> Bring it on you stupid GangOfFour bastards, with your idiotic bloated
> idioms that inculcate and contaminate perfectly good alternative
> languages!
> 
> Bring.
> 
> It.
> 
> On.
> 
Please, BE QUITE.
Maybe your solution is ok, but GoF just put an other way to do something.
Your solution take advantage from the package nature, the GoF's one try 
to take advantage from the OO nature. Anything else, nothing strange! 
Nothing is "stupid" or "bastard" if try to give a solution, specially if 
it works.
There are many solutions around, but please don't call anyone stupid or 
bastard... please, be quite.
Thanx a lot.

Luca { tatanka; } Stasio;   // stasio2000@tin.it



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  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
  0 siblings, 2 replies; 33+ messages in thread
From: Pylinius @ 2004-09-27  5:22 UTC (permalink / raw)


Luca Stasio wrote:
> Please, BE QUITE.
> Maybe your solution is ok, but GoF just put an other way to do something.
> Your solution take advantage from the package nature, the GoF's one try 
> to take advantage from the OO nature. Anything else, nothing strange! 
> Nothing is "stupid" or "bastard" if try to give a solution, specially if 
> it works.
> There are many solutions around, but please don't call anyone stupid or 
> bastard... please, be quite.
> Thanx a lot.
> 
> Luca { tatanka; } Stasio;   // stasio2000@tin.it

Please be QUITE?

Did you mean quiet? Try the library for quiet.

BTW, the GOF are a bunch of mental midgets.




^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-27  5:22     ` Pylinius
@ 2004-09-27  8:05       ` Luca Stasio
  2004-10-05 17:55       ` Luca Stasio
  1 sibling, 0 replies; 33+ messages in thread
From: Luca Stasio @ 2004-09-27  8:05 UTC (permalink / raw)


Pylinius wrote:
> Luca Stasio wrote:
> 
>> Please, BE QUITE.
>> Maybe your solution is ok, but GoF just put an other way to do something.
>> Your solution take advantage from the package nature, the GoF's one 
>> try to take advantage from the OO nature. Anything else, nothing 
>> strange! Nothing is "stupid" or "bastard" if try to give a solution, 
>> specially if it works.
>> There are many solutions around, but please don't call anyone stupid 
>> or bastard... please, be quite.
>> Thanx a lot.
>>
>> Luca { tatanka; } Stasio;   // stasio2000@tin.it
> 
> 
> Please be QUITE?
> 
> Did you mean quiet? Try the library for quiet.
> 
> BTW, the GOF are a bunch of mental midgets.
> 
Quiet!

Please, explain us why "the GoF are a bounch of mental midgets".
Have you some publications explaining this fact?
Have you some different way? I'm really interested... I use some of the 
GoF's solutions, but also other's one... sometimes mine... maybe I could 
use yours!
Let us appreciate your work.

Bye bye,
Luca { tatanka; } Stasio;  //stasio2000@tin.it



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: Ada Singleton Pattern
  2004-09-27  5:22     ` Pylinius
  2004-09-27  8:05       ` Luca Stasio
@ 2004-10-05 17:55       ` Luca Stasio
  1 sibling, 0 replies; 33+ messages in thread
From: Luca Stasio @ 2004-10-05 17:55 UTC (permalink / raw)


Hey MAN.... let us appreciate your work, please!

bye bye
Luca { tatanka; } Stasio;
(0)



^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2004-10-05 17:55 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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