mandatory/optionally overridable virtual functions
In a polymorphic hierarchy is it common practice to have public
virtual functions in the base class with a default empty
implementation and let the derived classes decide whether they want to
override it or not? In such cases what would be the access levels of
those functions in both base and derived classes?
struct AbstractBase
{
virtual void mandatory_func() = 0;
virtual void optional_func() { }
};
struct concretebase1 : public AbstractBase
{
virtual void mandatory_func() { }
};
struct concretebase2 : public AbstractBase
{
virtual void mandatory_func() { }
virtual void optional_func() { // do something cool }
};
on the face of it, it does seem natural but somehow I can't get it out
of my mind that I just keep adding virtual functions to AbstractBase
for every *specific* action I want to perform from one of the derived
classes. If I have a lot of such operations I am concerned there
would be a virutal function bloat in AbstractBase.
Are my fears misplaced?