My goal is to have a base client use a base class as an input. I would like to be able to extend the implementation of the base client through a derived client that takes a derived class as an input.
struct Base
{
int a, b, c;
...
};
struct Derived: public Base
{
int d, e;
...
};
class BaseClient
{
public:
BaseClient(const Base& b) : b(b)
{}
void processA(){...}
void processB(){...}
...
private:
Base b;
};
class DerivedClient : public BaseClient
{
public:
DerivedClient(const Derived& d) : BaseClient(d), d(d)
{}
void processD(){...}
void processE(){...}
...
private:
Derived d;
};
The bulk of the implementation is done in the BaseClient so taking advantage of that is a must. The problem I am having is that the Base class can get accessed in two different ways in the DerivedClient class. Once through the BaseClient and another through the Derived class data member. What is the best design practice in this situation?
Aucun commentaire:
Enregistrer un commentaire