What is the design template?

A few years ago I used interfaces like this:

class Base { public: virtual ~Base { } void foo() { doFoo(); } private: virtual void doFoo() = 0; }; 

then the output would be:

 class Derived : public Base { public: virtual ~Derived() { } private: virtual void doFoo() { } }; 

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

So what is the name of this design template?

+7
source share
2 answers

Your foo method should not be virtual. And in this case, the design pattern is called NVI - not a virtual interface

+8
source

This is a template template. Relevant excerpt from Wikipedia:

The template method defines the program skeleton algorithm. One or more steps of the algorithm can be overridden by subclasses to allow different behaviors while ensuring that the general algorithm is still respected.

I saw that this template used a lot to β€œforce” invoke an implementation of the base class (which usually should be executed explicitly in the output class).

+8
source

All Articles