Re: Singletons
Am 24.11.2012 19:52, schrieb Balog Pal:
On 11/22/2012 6:26 AM, Daniel Kr?gler wrote:
I also don't see how you can compile-time enforce the
essential invariant of a singleton - namely that only one object of
type X exists.
Err, what makes that an attribute of a singleton? And what possible
benefits could that create?
Signeton is an *object* that is accessible from anywhere in the
application, and *that* instance is surely the same.
This is certainly also some design pattern, but it is not the classic
singleton pattern. The classic source ("Design Pattern" from the Gang of
Four) defines the intent as
"Ensure a class only has one instance, and provide a global point to
access it"
Similarly the definition found here
http://en.wikipedia.org/wiki/Singleton_pattern
starts with
"the singleton pattern is a design pattern that restricts the
instantiation of a class to one object"
Like std::cout, cerr are proper singletons. But they share a class, and
you can have any number of other ostreams.
You may describe them as singletons but they are not so by the classic
design pattern definition.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]