Re: Singletons
Am 24.11.2012 19:47, schrieb Frank Birbacher:
Am 22.11.12 06:26, schrieb Daniel Kr?gler:
So you suggest that everyone who uses your singleton is supposed
to call the init function? The advantage of a singleton is to hide
such internal issues.
So, what if you need to pass arguments to initialization?
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.
The header does not even define a class type. So how could anyone
create an instance of it? The mapping that Matthew proposes is:
Logger::GetInstance().doFoo() becomes Logger::doFoo()
where Logger is changed from a class to a namespace. All data is
defined only in the cpp.
The concept is old. Before object orientation this approach was the
way to go.
I must say that I haven't understood that from the OP. I'm familiar with
what you describe above but I don't consider it as a classical singleton
and I surely had not recognized by the posting.
I agree that it has in common with the singleton pattern that it
provides a global point of access of functionality. It might be useful
to add in this context (and to keep some relation to C++ in this
discussion) that CORBA's ORB_init / destroy functions corresponds to
what the OP describes here.
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! ]