I'd like to configure the behaviour of objects at runtime by choosing a method to call out of a given set. Consider this simple example:
class Parameter;
class Conf;
class Obj {
public:
Obj( const Conf &t ): t_( t ) {}
void f( Parameter *d );
void f1( Parameter *d );
void f2( Parameter *d );
typedef void ( Obj::*Fn )( Parameter *d );
private:
const Conf &t_;
};
class Conf {
public:
Obj::Fn f;
};
void Obj::f( Parameter *d ) {
( this->*t_.f )( d );
}
By changing Conf::f
for a given Conf
object, the behaviour of all Obj
objects configured with this is changed.
First question: Does this resemble some design pattern (ok, it's kind of a method-pointer-strategy-thing...)? If so, should I consider a redesign?
Second question: I'd like to make this more flexible by using different parameter classes. I've already done this by making Parameter
a base class and doing type casting in the fN
methods, but that does not look like a final solution. Any suggestions?