From: Lew on
Diego wrote:
> if singletons are globals, then "no globals" is a mere illusion :-(

I don't know what that means. Static variables, singletons - both are globals
in some sense.

The singleton pattern isn't the magic bullet that so many people think.

--
Lew
From: Daniel T. on
Peter Duniho <NpOeStPeAdM(a)NnOwSlPiAnMk.com> wrote:
> Diego <jose.diego(a)gmail.com> said:
> > Daniel T. wrote:

> > > Just out of curiosity, which method would you have chosen if
> > > someone had told you up front "no globals"? (After all, a
> > > singleton is just a global with a pretty wrapper.)
> >
> > if singletons are globals, then "no globals" is a mere illusion
> > :-(
>
> There's no official definition of a "global", so it's more a matter
> of semantics than of illusion.

The whole point of a singleton is to "Ensure a class only has one
instance, <i>and provide a global point of access to it.</i>" (GoF pg.
127 emphasis added.) Global access, means global IMO.

And the question still stands to the OP, if you had known from the
outset of the new feature, how would you have implemented it?
From: Peter Duniho on
On 2007-11-01 13:20:33 -0700, "Daniel T." <daniel_t(a)earthlink.net> said:

> The whole point of a singleton is to "Ensure a class only has one
> instance, <i>and provide a global point of access to it.</i>" (GoF pg.
> 127 emphasis added.) Global access, means global IMO.

I understand that "singleton" has a perhaps a very specific meaning in
the particular book in which (it seems) this whole idea of "design
patterns" was first suggested.

However, I see nothing to prevent someone from implementing a singleton
that is not accessible globally. And I would still call it a singleton.

Furthermore, in C# any singleton itself is not accessible globally; you
need to start with the namespace, and then a particular class name, at
a minimum.

I don't see the point in raising the question of whether globals can
exist in C# anyway, but assuming the question has been raised it seems
silly to insist that the singleton pattern is somehow related to the
question. You have to define "global" first before you can say whether
the singleton pattern exists if and only if globals do, and once you've
defined "global", you don't need to look at the singleton pattern to
decide whether they exist in a language or not.

Pete

From: Roedy Green on
On Thu, 01 Nov 2007 01:45:54 -0000, Bilz <BrianGenisio(a)gmail.com>
wrote, quoted or indirectly quoted someone who said :

>Ok, that is fine... but how does all of the classes get the key? Do
>you pass them in to every constructor, and keep track of the key all
>the way down the object graph?

you pass your parameters to the factory. It composes the key to see if
it built a suitable config object before, if not it calls the
constructor with the parms and adds it to the pool.

Imagine how you might cache Font bitmaps using family, size, style as
the key.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
From: Arne Vajhøj on
Peter Duniho wrote:
> On 2007-11-01 13:20:33 -0700, "Daniel T." <daniel_t(a)earthlink.net> said:
>> The whole point of a singleton is to "Ensure a class only has one
>> instance, <i>and provide a global point of access to it.</i>" (GoF pg.
>> 127 emphasis added.) Global access, means global IMO.
>
> I understand that "singleton" has a perhaps a very specific meaning in
> the particular book in which (it seems) this whole idea of "design
> patterns" was first suggested.

They defined it and gave it the name.

It is a well known source.

It would be pure obfuscation to use the same well known term about
something different.

> Furthermore, in C# any singleton itself is not accessible globally; you
> need to start with the namespace, and then a particular class name, at a
> minimum.

That has nothing to do with accessibility.

Arne