C++ 模板方法
2014-08-07 22:51
99 查看
本文参考:
本文参考2:
本文参考2:
/* 模版设计模式:定义一个操作中的算法框架,具体的算法细节在子类中实现。 模版方法使得子类可以不改变一个算法的结构即可重定义算法的某些特定的步骤 Created by Phoenix_FuliMa */ #include <iostream> using namespace std; class TemplateMethod { public: virtual void step_1() {} virtual void step_2() {} void templatmethod() { step_1(); step_2(); cout<<"algorithm end!"<<endl; } }; class TemplateMethod1:public TemplateMethod { public: void step_1() { cout<<"method 1 step_1"<<endl; } void step_2() { cout<<"method 1 step_2"<<endl; } }; class TemplateMethod2:public TemplateMethod { public: void step_1() { cout<<"method 2 step_1"<<endl; } void step_2() { cout<<"method 2 step_2"<<endl; } }; int main() { TemplateMethod1 *method1 = new TemplateMethod1(); TemplateMethod2 *method2 = new TemplateMethod2(); method1->templatmethod(); method2->templatmethod(); system("pause"); return 0; }
相关文章推荐
- 金庸小说考试之模板方法模式学习笔记[C++版]
- 【C++】Chapter7:模板方法模式
- C++模板实现的通用工厂方法模式
- 行为模式之模板方法模式(Template Pattern)C++实现
- C++模板常用使用方法介绍
- C++主题——Template Method(模板方法)模式
- 设计模式之模板方法模式,C++实现
- c++设计模式:模板方法模式(Template Method Pattern)
- c++设计模式:模板方法模式(Template Method Pattern)
- C++高效实现模板方法模式
- 【读书笔记】模板方法模式代码(C++)
- 设计模式C++实现(5)——原型模式、模板方法模式
- 设计模式C++实现(5)——原型模式、模板方法模式
- eclipse develop for C\C++ 文件注释函数注释代码模板自动生成方法
- 设计模式C++实现(5)——原型模式、模板方法模式
- C++实现模板顺序表和三种排序方法
- 设计模式C++实现(5)——原型模式、模板方法模式
- C++模板应用——让模板定义和实现分离的方法
- c++ 实现模板方法模式
- C++模板常用使用方法介绍