Requirement : Some of the functionality of grand parent class (i.e. Base) need to be changed for layer 2. This changed functionality is same for both Dervied_Layer_2_Case_A and Dervied_Layer_2_Case_B.
Do you see any negative impact of using below type of solution ? I am asking this becoz I haven't seen such pattern before.
struct Base
{
virtual void doSomething() { ... }
};
///// Layer 1 ////////////////////
template <class BaseType = Base>
struct Dervied_Layer_1_Case_A : public BaseType
{
static_assert(std::is_base_of<Base, BaseType>::value);
//This class uses other functionality from Base. Hence the derivation
void runA() {calls BaseType::doSomething() while working}
};
template <class BaseType = Base>
struct Dervied_Layer_1_Case_B : public BaseType
{
static_assert(std::is_base_of<Base, BaseType>::value);
//This class uses other functionality from Base. Hence the derivation
void runB() {calls BaseType::doSomething() while working}
};
////////Layer 2 //////////////
struct BaseLayer2 : public Base
{
//Only below behavior need to be changed. Other functionality of Base used without change
void doSomething() override { ...differnet implementation.. }
};
struct Dervied_Layer_2_Case_A : public Dervied_Layer_1_Case_A <BaseLayer2>
{
//some of the functionality of DerviedCase_1_A is changed
};
struct Dervied_Layer_2_Case_B : public Dervied_Layer_1_Case_B <BaseLayer2>
{
//some of the functionality of DerviedCase_1_B is changed
}