Реализации на С++
Template Method
Общая реализация на языке С++
class AbstractClass
{
public:
void templateMethod()
{
primitiveOperation();
concreteOperation();
hook();
}
virtual ~AbstractClass() = default;
protected:
virtual void primitiveOperation() = 0;
void concreteOperation()
{
cout << "concreteOperation;" << endl;
}
virtual void hook()
{
cout << "hook Base;" << endl;
}
};
#include <iostream>
using namespace std;
int main()
{
ConcreteClassA ca;
ConcreteClassB cb;
ca.templateMethod();
cb.templateMethod();
}
Last updated
Was this helpful?