In C ++, suppose I have a Derived class that implements the BaseInterface interface class , where BaseInterface has only pure virtual functions and a virtual destructor:
class BaseInterface
{
public:
virtual void doSomething() = 0;
~BaseInterface(){}
};
class Derived : public BaseInterface
{
public:
Derived() {}
~Derived(){}
protected:
virtual void doSomething();
private:
int x;
};
No classes outside the Derived class hierarchy should access Derived :: doSomething () directly, that is, it should only be accessed polymorphically through the BaseInterface class. To enforce this rule, I made Derived :: doSomething () protected. This works well, but I'm looking for pro / con opinions on this approach.
Thank!
Ken
Kenk source
share