|
Boost : |
From: Stewart, Robert (stewart_at_[hidden])
Date: 2001-11-28 09:12:41
Philip Nash wrote:
>
> > > 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.
Why not access all singletons through smart pointers? That is, the one
instance -- per thread, if desired -- is found by a smart pointer. All
accesses to the singleton are as pointers -- sorry to those that prefer
references -- but there would be consistency. Furthermore, the smart
pointer can provide all sorts of policies about how the referenced object is
created, destroyed, located, etc. A simple version might just access an
instance() mf to get to the underlying singleton pointer or reference.
IOW, while you may wish to implement the controlled class such that
programmer's can't instantiate it themselves, making any class a singleton
is as simple as wrapping it in a singleton smart pointer. Furthermore, if
the class ever becomes something other than a singleton, all you need to do
is change the pointer type being used; all code using the object remains
unchanged.
Rob
Susquehanna International Group, LLP
http://www.sig.com
IMPORTANT: The information contained in this email and/or its attachments is
confidential. If you are not the intended recipient, please notify the
sender immediately by reply and immediately delete this message and all its
attachments. Any review, use, reproduction, disclosure or dissemination of
this message or any attachment by an unintended recipient is strictly
prohibited. Neither this message nor any attachment is intended as or
should be construed as an offer, solicitation or recommendation to buy or
sell any security or other financial instrument. Neither the sender, his or
her employer nor any of their respective affiliates makes any warranties as
to the completeness or accuracy of any of the information contained herein
or that this message or any of its attachments is free of viruses.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk