tags:

views:

63

answers:

3

Which should I use?

struct IFilterTreeNode
{
    virtual unsigned int GetEasiestProveRank() const = 0;
    virtual unsigned int GetEasiestDisproveRank() const = 0;
    virtual unsigned int GetEasiestProveNumber() const = 0;
    virtual unsigned int GetEasiestDisproveNumber() const = 0;
    virtual std::vector<IFilterTreeNode *> GetChildren() const = 0;
    virtual bool AttemptToProve() = 0;
    virtual bool AttemptToDisprove() = 0;
    virtual ~IFilterTreeNode() {};
};

or:

class IFilterTreeNode
{
    virtual unsigned int GetEasiestProveRankImpl() const = 0;
    virtual unsigned int GetEasiestDisproveRankImpl() const = 0;
    virtual unsigned int GetEasiestProveNumberImpl() const = 0;
    virtual unsigned int GetEasiestDisproveNumberImpl() const = 0;
    virtual std::vector<IFilterTreeNode *> GetChildrenImpl() const = 0;
    virtual bool AttemptToProveImpl() = 0;
    virtual bool AttemptToDisproveImpl() = 0;
public:
    unsigned int GetEasiestProveRank() const
    {
        return GetEasiestProveRankImpl();
    }
    unsigned int GetEasiestDisproveRank() const
    {
        return GetEasiestDisproveRankImpl();
    }
    unsigned int GetEasiestProveNumber() const
    {
        return GetEasiestProveNumberImpl();
    }
    unsigned int GetEasiestDisproveNumber() const
    {
        return GetEasiestDisproveNumberImpl();
    }
    std::vector<IFilterTreeNode *> GetChildren() const
    {
        return GetChildrenImpl();
    }
    bool AttemptToProve()
    {
        return AttemptToProveImpl();
    }
    bool AttemptToDisprove()
    {
        return AttemptToDisproveImpl();
    }
    virtual ~IFilterTreeNode() {};
};
+1  A: 

The goal of the NVI idiom is to seperate interface and implementation. According to object oriented design practices, this is something you want.

If you feel there is no real reason to do that in this case, I'd do the former. Herb Sutter argues quite the opposite.

You also might ask, "how simple is simple?" Simple can frequently become complex. Maybe start with the former, and don't change it to the latter until you need the latter.

sheepsimulator
Lol -- Herb Stutter's article is precisely why I asked the question :)
Billy ONeal
A: 

Probably not worth the trouble in this simple case. Were there any parameters to the methods and/or a need for extensible logging/instrumentation/parameter pre/post-processing, I would use NVI.

Nikolai N Fetissov
+1  A: 

I'm lazy, and most of our codebase uses the first choice, so that's the one I'd go with. I'd switch to the second choice immediately when things start getting more complex. But like I said, I'm lazy. :-)

The second choice is definitely more future-proof and more flexible. Good programmers make classes easy to use. Making them easy to write is secondary.

Kristo
+1. Laziness is the most important virtue for software development. "Easy to write vs. easy to use" deserves +1 on its own.
Dummy00001