A design question -
Hello,
I am quite new to C++ and am adding some new features to a library and
to some programs that call it. This library is our common one and is
used by all programs at our site. The new feature which I am adding is
only being used by a single program. But whenever the call reaches the
library and it reaches every so often, it must try to invoke this new
feature if its available.
I thought I will define a base class in the library which is more of
an interface. And whenever this feature is added in the various
programs, I would derive a new class specific to the program
functionality. And in each of these programs this has to be a
singleton
-------------------------------
In the library:
class Base{
public:
static Base * getInstance() { return sp; /* assume that its returned
thread safe */}
virtual void runTerm(){}
protected:
static atomic_refBase * sp;
string msg1;
};
Base * Base::sp = NULL;
---------------------------------
In the library to invoke this feature:
Base * bp = Base::getInstance();
if( bp != NULL){
bp->runTerm();
}
--------------------------------
Now in the various programs:
class Derived : public Base{
Base * getInstance(){ /* here implement a singleton and assign the
pointer to it to sp */
void runTerm() { /*implement functionality specific to this program*/
};
-------------------------------------------------------
Now my question is - is there a better way to do this? What may be the
pitfalls in this?
The programs where this gets implemented are all multi threaded
Thanks
John
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]