Following is the pseudo code to describe the problem:
class Client
{
public:
void F1(A*); //import
void F2(A*); //export
void F3(A*); //print
void ...
void F100(A*); //validate
};
Client::F3(A* p)
{
p->F3();
}
class A
{
public:
int memberA;
virtual void F3();
};
class B : public A
{
public:
int memberB;
virtual void F3();
};
class C : public B
{
public:
int memberC;
virtual void F3();
};
void A:F3()
{
print(memberA);
}
void B:F3()
{
A:F3();
print(memberB);
}
void C:F3()
{
B:F3();
print(memberC);
}
The client is using class A and possibly its derivatives, and it has 100 ways of using it. E.g. import/export/print/validate etc.
Keep in mind that the sub class will call the base class plus something of its own.
I know a way to implement this is to let class A/B/C all implement these 100 functions. For example: F3, the print functionality and their implementations.
The problem is that if I implement all these 100 functions in all classes in the inheritance chain (these A/B/C is just a simplified model, in real world, there could be more than 10 layers of inheritance), each single class will become too fat.
Could you help me to refactor it?