comp.lang.ada
 help / color / mirror / Atom feed
From: Luca Stasio <stasio2000@tin.it>
Subject: Re: Ada Singleton Pattern
Date: Wed, 15 Sep 2004 19:38:51 GMT
Date: 2004-09-15T19:38:51+00:00	[thread overview]
Message-ID: <fT02d.328253$5D1.14478004@news4.tin.it> (raw)
In-Reply-To: <uk6uwezty.fsf@earthlink.net>

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



  reply	other threads:[~2004-09-15 19:38 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
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 [this message]
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