Parent implementation different to child implementation I have the following interface:

struct IFilter
{
    virtual enterClass(ClassData&amp;, int recursiveLevel) = 0;
    virtual enterStructure(ClassData&amp;, int recursiveLevel) = 0;
    virtual enterVariable(ClassData&amp;, int recursiveLevel) = 0;
    virtual enterFunction(ClassData&amp;, int recursiveLevel) = 0;
};


And here is an example of an implementation:

struct ReadOnlyFilter: public IFilter
{
    virtual enterClass(ClassData&amp; classData, int recursiveLevel)
    {
        if(recursiveLevel==0 || classData-&gt;isReadondOnly())
        {
            this.out &lt;&lt; "Class " &lt;&lt; classData-&gt;name() &lt;&lt; "\n{";
        }
    }


So items can contain classes, structs, variables and functions. A class or struct can contain items as children and grandchildren and so on. The class ReadOnlyFilter is used by a function which will loop recursively over all of the children and grandchildren etc of an item. The recursiveLevel is incremented as we go deeper and deeper, like this:

Class c (recursiveLevel=0)
{
    Variable v1 (recursiveLevel=1)
    Class cChild (recursiveLevel=1)
    {
       Class cGrandChild (recursiveLevel=2)


All my implementations have one thing in common: they should always write to this.out if the recursiveLevel is zero. This is why I have if(recursiveLevel==0 || in my code. This results in ifs everywhere in my code.

To solve this, I was thinking of doing something like this instead and was wondering if you think this is a good solution:

(I'm using C++98 and Boost)

struct IFilter
{
    virtual enterClass(ClassData&amp;, int recursiveLevel) = 0;
    virtual enterStructure(ClassData&amp;, int recursiveLevel) = 0;
    virtual enterVariable(ClassData&amp;, int recursiveLevel) = 0;
    virtual enterFunction(ClassData&amp;, int recursiveLevel) = 0;

    virtual enterChildClass(ClassData&amp;, int recursiveLevel) = 0;
    virtual enterChildStructure(ClassData&amp;, int recursiveLevel) = 0;
    virtual enterChildVariable(ClassData&amp;, int recursiveLevel) = 0;
    virtual enterChildFunction(ClassData&amp;, int recursiveLevel) = 0;
};

struct BaseFilter: public IStyler
{
    virtual enterClass(ClassData&amp; classData, int recursiveLevel)
    {
        out &lt;&lt; "Class " &lt;&lt; classData-&gt;name() &lt;&lt; "\n{";
    }

struct ReadOnlyFilter: public BaseFilter
{
    virtual enterChildClass(ClassData&amp; classData, int recursiveLevel)
    {
        if(classData-&gt;isReadondOnly())
        {
            enterClass(classData, recursiveLevel);
        }
    }
I'm not sure what your question is about recursiveLevel, but printing only when recursiveLevel == 0 seems like pretty weird behaviour to me.  If you only care about the outermost level of your data structure, then why even bother recursing?

I'm also puzzled by what you are trying to accomplish by introducing the enterChild...() methods.  What does "child" mean — that the method should only be called when recursiveLevel &gt; 0?

Or perhaps you mean to have ReadOnlyFilter::enterClass() chain to the superclass implementation?

struct ReadOnlyFilter: public BaseFilter {
    virtual enterClass(ClassData&amp; classData, int recursiveLevel) {
        if (classData-&gt;isReadOnly()) {  // isReadondOnly() in original code
            BaseFilter::enterClass(classData, recursiveLevel);
        }
    }
    // etc.
}