Template_Method
#include <iostream> using namespace std;
#define DESTROY_POINTER(ptr) if (ptr) { delete ptr; ptr = NULL; } class TemplateMethod
{
public:
void AlgorithmA() { Step1(); Step2(); Step3(); }
void AlgorithmB() { Step3(); Step2(); Step1(); } protected:
virtual void Step1()=;
virtual void Step2()=;
virtual void Step3()=;
}; class ConcreteTemplateA : public TemplateMethod
{
public:
ConcreteTemplateA() {}
~ConcreteTemplateA() {} protected:
void Step1() { cout<<"ConcreteTemplateA::Step1"<<endl; }
void Step2() { cout<<"ConcreteTemplateA::Step2"<<endl; }
void Step3() { cout<<"ConcreteTemplateA::Step3"<<endl; }
}; class ConcreteTemplateB : public TemplateMethod
{
public:
ConcreteTemplateB() {}
~ConcreteTemplateB() {} protected:
void Step1() { cout<<"ConcreteTemplateB::Step1"<<endl; }
void Step2() { cout<<"ConcreteTemplateB::Step2"<<endl; }
void Step3() { cout<<"ConcreteTemplateB::Step3"<<endl; }
}; int main(int argc, char *argv[])
{
TemplateMethod* pTemplate = NULL; pTemplate = new ConcreteTemplateA;
pTemplate->AlgorithmA();
DESTROY_POINTER(pTemplate); pTemplate = new ConcreteTemplateB;
pTemplate->AlgorithmB();
DESTROY_POINTER(pTemplate); return ;
}
Template_Method的更多相关文章
- 【行为型】TemplateMethod模式
模板方法意图是为算法定义好骨架结构,并且其中的某些步骤延迟到子类实现.该模式算是较为简单的一种设计模式.在实际中,应用也较为频繁.模式的类关系图参考如下: 模式的编码结构参考如下: namespace ...
- 设计模式 - 模板方法模式(template method pattern) JFrame 具体解释
模板方法模式(template method pattern) JFrame 具体解释 本文地址: http://blog.csdn.net/caroline_wendy 參考模板方法模式(templ ...
- [Python设计模式] 第10章 怎么出试卷?——模版方法模式
github地址:https://github.com/cheesezh/python_design_patterns 题目 小时候数学老师的随堂测验,都是老师在黑板上写题目,学生在下边抄,然后再做题 ...
- 设计模式 - 模板方法模式(template method pattern) 排序(sort) 具体解释
模板方法模式(template method pattern) 排序(sort) 具体解释 本文地址: http://blog.csdn.net/caroline_wendy 參考模板方法模式(tem ...
- 设计模式 - 模板方法模式(template method pattern) 具体解释
模板方法模式(template method pattern) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy 模板方法模式(template metho ...
- Template Method模式和Strategy模式有何异同
Template Method模式和Strategy模式有何异同 博客分类: 设计模式 Java Template Method模式很容易理解,就是由基类提供一个模板,将各子类中不变的行为提取到基类 ...
- PHP 23种设计模式
学习PHP,对设计模式永远是逃不掉的:今天把php23种设计模式及其demo好好整理如下: 记录PHP关于23种设计模式的简单Demo. Demo地址:https://segmentfault.com ...
随机推荐
- Python标准库——走马观花
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Python有一套很有用的标准库(standard library).标准库会随着 ...
- Spring中PropertyPlaceholderConfigurer的使用
Spring中PropertyPlaceholderConfigurer的使用 在使用Spring配置获取properties文件时,在网上查到相关的资料,分享哈!! (1)获取一个配置文件 ...
- PHP 时区设置
有时候使用date("Y-m-d h:i:s")时发现时间相差8小时,修改“/etc/php5/apache2/php.ini”: date.timezone = "As ...
- 内存调试工具---valgrind
安装 1.到www.valgrind.org下载最新版valgrind-3.2.3.tar.bz2 2.解压安装包:tar –jxvf valgrind-3.2.3.tar.bz2 3.解压后生成目录 ...
- linux内核神级list
源码: #ifndef _LINUX_LIST_H #define _LINUX_LIST_H /* * Simple doubly linked list implementation. * * S ...
- 92、App Permissions(权限管理)实例
•Manifest权限声明 •Permission Groups-权限组 •权限的区分-安装时授权于运行时授权 •撤销权限 •检查.请求权限 •在应用中如何合理的处理权限请求逻辑 在Android ...
- go get 获得 golang.org 的项目
go get 用来动态获取远程代码包的,目前支持的有BitBucket.GitHub.Google Code和Launchpad.这个命令在内部实际上分成了两步操作:第一步是下载源码包,第二步是执行g ...
- I2C协议(转)
1.I2C协议 2条双向串行线,一条数据线SDA,一条时钟线SCL. SDA传输数据是大端传输,每次传输8bit,即一字节. 支持多主控(multimastering),任何时间点只能有一 ...
- memcpy、memmove、memset
void * memcpy(void * dst, const void * src, size_t count) { void *res=dst; while (count--) { *(char* ...
- MFC编译程序,缺少MFC动态链接库的解决
MFC编译程序,缺少MFC动态链接库的解决 问题:VS2010 c++编写的程序在别人的机子运行不了,缺少mfc100u.dll xxx100d.dll等的解决方法 解决方法: 1.将这些dll打包, ...