Hello,
I have a base class Base with given member variables, getters and setters, but it doesn't do much on its own. Then there are functionalities (Func) which can use this base class's member functions to achieve some complex computation.
I would like to design this class structure in a way that a derived of Base, Derived can have added functionality with the use of Funcs, without further programming.
Here's what I thought would work:
This compiles, and does what I want most of the time. However, is there a way to override a member function of Base (for example for logging purposes) in an added functionality class G, derived of FunctionalityBa se?
Is this a good design? Are there any (better) alternatives?
Thanks in advance,
Harinezumi
I have a base class Base with given member variables, getters and setters, but it doesn't do much on its own. Then there are functionalities (Func) which can use this base class's member functions to achieve some complex computation.
I would like to design this class structure in a way that a derived of Base, Derived can have added functionality with the use of Funcs, without further programming.
Here's what I thought would work:
Code:
class Base { public: Base(int par1, int par2) : par1(par1), par2(par2) {} virtual void GetPar1() { return par1; } virtual void GetPar2() { return par2; } private: int par1, par2; }; class FunctionalityBase { public: FunctionalityBase(B* base) : basePointer(base) {} protected: Base* basePointer; }; class AddedFunctionality1 : public FunctionalityBase { public: AddedFunctionality1(Base* base) : FunctionalityBase(base) {} void AFunctionality() { /*do something through the base pointer*/} }; class Derived : public Base, public AddedFunctionality1 { public: Derived(int par1, int par2) : Base(par1, par2), AddedFunctionality(this) {} };
Is this a good design? Are there any (better) alternatives?
Thanks in advance,
Harinezumi
Comment