本文介绍了这是什么设计模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年前,我曾经创建过这样的界面:

Several years ago, I used to create interfaces like this :

class Base
{
  public:
    virtual ~Base
    {
    }

    void foo()
    {
      doFoo();
    }

  private:
    virtual void doFoo() = 0;
};

那么派生将是:

class Derived : public Base
{
  public:
    virtual ~Derived()
    {
    }

  private:
    virtual void doFoo()
    {
    }
};

我相信我在某个地方看到这是一个设计模式,但现在我找不到任何地方,

I am sure I saw this as a design pattern somewhere, but now I can not find it anywhere, and can not remember how it is called.

推荐答案

方案

您的 foo 方法不应该是虚拟的。在这种情况下,设计模式称为NVI - 非虚拟接口

Your foo method shouldn't be virtual. And in this case the design pattern is called NVI - non-virtual interface

这篇关于这是什么设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 18:15