From: sjw <simon.j.wright@mac.com>
Subject: Re: Ada-Singleton-Why does it work like this?
Date: Wed, 25 Mar 2009 15:29:25 -0700 (PDT)
Date: 2009-03-25T15:29:25-07:00 [thread overview]
Message-ID: <5ccc901e-9fb6-4f43-8dcd-5a92a5a4f06e@e12g2000vbe.googlegroups.com> (raw)
In-Reply-To: WFbyl.30045$DP1.2209@attbi_s22
On Mar 24, 8:47 pm, "Jeffrey R. Carter"
<spam.jrcarter....@spam.acm.org> wrote:
> patrick.gu...@googlemail.com wrote:
> > Hi all,
> > 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. I used this code and it all worked as
> > expected. My problem is, that I don´t ave any idea, why it does...here
> > is my code:
>
> > package Singleton is
>
> > type Singleton_Type (<>) is tagged limited private;
> > type Singleton_Access is access all Singleton_Type;
>
> > function return_Single return Singleton_Access;
>
> > procedure setValues(input : in out Singleton_Access; valueIN :
> > Integer; valueIN2 : Integer);
> > procedure print_something(input : Singleton_Access);
>
> > private
> > type Singleton_Type is tagged limited record
> > value : Integer;
> > value2 : Integer;
> > end record;
>
> > end Singleton;
>
> This is a very poor solution to the problem. A much simpler solution is
>
> package Singleton is
> procedure Set (Value_1 : in Integer; Value_2 : in Integer);
>
> procedure Print;
> end Singleton;
Usually the application problem is to do something (eg print stuff)
and there's a side note that there's only one printer.
We could decide to apply the singleton-in-package pattern above to
ensure the limit is met.
In general, though, having only one printer isn't an integral part of
the application problem, and it'll be a real pain when it turns out
you need to add one. Better to be general about it.
My code generator allowed for singletons (no visible creation/deletion
operations, "instance" operations don't need a This parameter, ...)
because I thought it would be useful, but in fact it's been a feature
I deeply regret; it introduces inconsistency and irregularity. Now I
prefer to specify that there is a bounded number of instances and make
the bounds 0..1.
next prev parent reply other threads:[~2009-03-25 22:29 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-24 19:01 Ada-Singleton-Why does it work like this? patrick.gunia
2009-03-24 19:10 ` Pascal Obry
2009-03-24 20:47 ` Jeffrey R. Carter
2009-03-25 0:10 ` Martin
2009-03-25 0:41 ` Jeffrey R. Carter
2009-03-25 9:30 ` Dmitry A. Kazakov
2009-03-26 8:55 ` Martin
2009-03-26 9:28 ` Dmitry A. Kazakov
2009-03-26 13:39 ` Maciej Sobczak
2009-03-26 14:07 ` Georg Bauhaus
2009-03-26 14:33 ` Dmitry A. Kazakov
2009-03-26 15:22 ` Georg Bauhaus
2009-03-26 16:31 ` Dmitry A. Kazakov
2009-03-26 14:28 ` Dmitry A. Kazakov
2009-03-26 22:00 ` Maciej Sobczak
2009-03-27 10:02 ` Dmitry A. Kazakov
2009-03-25 22:29 ` sjw [this message]
2009-03-24 20:52 ` Ludovic Brenta
2009-03-25 9:59 ` patrick.gunia
2009-03-25 10:29 ` Jean-Pierre Rosen
2009-03-25 11:26 ` Georg Bauhaus
2009-03-25 11:49 ` patrick.gunia
2009-03-29 7:29 ` Jacob Sparre Andersen
2009-03-24 21:21 ` Dmitry A. Kazakov
2009-03-25 10:07 ` patrick.gunia
2009-03-25 10:57 ` patrick.gunia
2009-03-25 11:40 ` Georg Bauhaus
2009-03-25 11:46 ` Ludovic Brenta
2009-03-25 11:55 ` patrick.gunia
2009-03-25 14:10 ` patrick.gunia
2009-03-25 14:40 ` Ludovic Brenta
2009-03-25 15:16 ` Adam Beneschan
2009-03-25 15:19 ` patrick.gunia
2009-03-25 16:52 ` Georg Bauhaus
2009-03-25 11:10 ` Dmitry A. Kazakov
2009-03-25 11:37 ` patrick.gunia
2009-03-25 12:07 ` Ludovic Brenta
2009-03-25 15:00 ` Robert A Duff
2009-03-25 11:17 ` Jean-Pierre Rosen
2009-03-26 9:04 ` Martin
2009-03-25 11:38 ` Ludovic Brenta
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox