Boost logo

Boost :

From: Thomas Matelich (toms-mailing-lists_at_[hidden])
Date: 2001-11-16 13:02:40


"Gennadiy E. Rozental" wrote:

> --- In boost_at_y..., Thomas Matelich <toms-mailing-lists_at_h...> wrote:
> > Peter Dimov wrote:
> >
> > > > In that respect, this code clearly communicates that "A isa
> > > > singleton":
> > > >
> > > > class A : public singleton<A> {
> > > > /* ... */
> > > > };
> > >
> > > Is this a library interface? If it is, why do you need the class name at
> > > all? You know that there is a single instance of A.
> > >
> > > Instead of
> > >
> > > class A: public /* public? */ singleton<A>
> > > {
> > > void f();
> > > };
> > >
> > > A::instance().f();
> > >
> > > why not simply
> > >
> > > namespace A
> > > {
> > > void f();
> > > }
> > >
> > > f();
> >
> > Funny you should mention this. We (my coworkers and I) have been
> > pretty bad about using too many singletons, and I recently rewrote one of them
> like
> > that. I just might be hooked. I'm getting really tired of A::Instance()
> especially
> > since A is usually something like ProcedureManager.
>
> Maybe you just need Monostate pattern mentioned in one of previos
> postings instead of Singleton?

I suppose the namespace/functions thingy is pretty much identical to the Monostate. I
had previously thought a Monostate was just a place to put constants. I'm troubled by
trying to figure out which [Insert global data pattern here] uses in my code should go
away. I've read all the c2 wiki pages about Singletons and am still perplexed.

--
Thomas O Matelich
Senior Software Designer
Zetec, Inc.
matelich_at_[hidden]
tmatelich_at_[hidden]

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk