gpt4 book ai didi

c++ - NVI 习语是否应该用于简单的接口(interface)类?

转载 作者:搜寻专家 更新时间:2023-10-31 00:47:50 24 4
gpt4 key购买 nike

我应该使用哪个?

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() {};
};

或:

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() {};
};

最佳答案

我很懒,我们的大部分代码库都使用第一个选项,所以我会选择第一个。当事情开始变得越来越复杂时,我会立即切换到第二个选择。但就像我说的,我很懒惰。 :-)

第二种选择绝对更适合 future ,也更灵活。优秀的程序员使类易于使用。让它们易于编写是次要的。

关于c++ - NVI 习语是否应该用于简单的接口(interface)类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3427047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com