#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的更多相关文章

  1. 【行为型】TemplateMethod模式

    模板方法意图是为算法定义好骨架结构,并且其中的某些步骤延迟到子类实现.该模式算是较为简单的一种设计模式.在实际中,应用也较为频繁.模式的类关系图参考如下: 模式的编码结构参考如下: namespace ...

  2. 设计模式 - 模板方法模式(template method pattern) JFrame 具体解释

    模板方法模式(template method pattern) JFrame 具体解释 本文地址: http://blog.csdn.net/caroline_wendy 參考模板方法模式(templ ...

  3. [Python设计模式] 第10章 怎么出试卷?——模版方法模式

    github地址:https://github.com/cheesezh/python_design_patterns 题目 小时候数学老师的随堂测验,都是老师在黑板上写题目,学生在下边抄,然后再做题 ...

  4. 设计模式 - 模板方法模式(template method pattern) 排序(sort) 具体解释

    模板方法模式(template method pattern) 排序(sort) 具体解释 本文地址: http://blog.csdn.net/caroline_wendy 參考模板方法模式(tem ...

  5. 设计模式 - 模板方法模式(template method pattern) 具体解释

    模板方法模式(template method pattern) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy 模板方法模式(template metho ...

  6. Template Method模式和Strategy模式有何异同

    Template Method模式和Strategy模式有何异同 博客分类: 设计模式 Java  Template Method模式很容易理解,就是由基类提供一个模板,将各子类中不变的行为提取到基类 ...

  7. PHP 23种设计模式

    学习PHP,对设计模式永远是逃不掉的:今天把php23种设计模式及其demo好好整理如下: 记录PHP关于23种设计模式的简单Demo. Demo地址:https://segmentfault.com ...

随机推荐

  1. iOS 数字字符串的直接运算 + - * /

    NSDecimalNumber *d1 = [NSDecimalNumber decimalNumberWithString:@"3.14"]; NSDecimalNumber * ...

  2. C#中调用Windows API的要点 .

    介绍 API(Application Programming Interface),我想大家不会陌生,它是我们Windows编程的常客,虽然基于.Net平台的C#有了强大的类库,但是,我们还是不能否认 ...

  3. 跨域请求 & jsonp

    0 什么是跨域请求 在一个域名下请求另外一个域名下的资源,就是跨域请求.example 1:比如:我当前的域名是http://che.pingan.com.我现在要去请求http://www.cnbl ...

  4. JS获取两个日期的月份差

    function getMonthBetween(startDate,endDate){ startDate=new Date(startDate.replace(/-/g,'/')); endDat ...

  5. 脱离rails 使用Active Record

    目录结构 database.yml development: adapter: sqlite3 database: db/test.db pool: 5 timeout: 5000 001_schem ...

  6. Java错误:很奇怪的错误。。。

    刚刚调试java web中出现了一个很奇怪的现象,前端有一个页面通过ajax调用后台的servlet,当我把后台的servlet代码修改后(将返回值由a修改为b),前端页面仍然获取的是a.调试跟踪se ...

  7. router os

    http://www.oschina.net/news/47568/router-operation-system

  8. 修复:"Failed to start Load Kernel Modules"

    使用非默认内核而出现的错误. [zsj@arch ~]$ systemctl --state=failed UNIT LOAD ACTIVE SUB DESCRIPTION● systemd-modu ...

  9. UIButton 详解

    1)创建 UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 风格有如下 typedef enum { UIButt ...

  10. NAT学习笔记

    NAT介绍 NAT, 全称网络地址转换(Network Address Translation),是一种在IP封包通过路由器或防火墙时重写来源IP地址或目的IP地址的技术. NAT的分类及介绍 NAT ...