<Head First 设计模式>:模板方法模式:Beverage
来源:互联网 发布:mac装双系统的利弊 编辑:程序博客网 时间:2024/05/16 01:39
#ifndef __COFFINEBEVERAGE_H__#define __COFFINEBEVERAGE_H__#include <iostream>using namespace std;class Beverage{public:Beverage(){}virtual ~Beverage(){}void Prepare(){BoilWater();Brew();PourInCup();AddCondiments();}virtual void Brew() = 0;virtual void AddCondiments() = 0;void BoilWater(){cout << "Boil Water." << endl;}void PourInCup(){cout << "Pour In Cup." << endl;}};class Coffe : public Beverage{public:Coffe(){}virtual ~Coffe(){}virtual void Brew(){cout << "Dripping Water through filter" << endl;}virtual void AddCondiments(){cout << "Add sugar and milk" << endl;}};class Tea : public Beverage{public:Tea(){}virtual ~Tea(){}virtual void Brew(){cout << "Steeping the tea." << endl;}virtual void AddCondiments(){cout << "Add lemon." << endl;}};#endif
#include <iostream>#include "Beverage.h"using namespace std;int main(){Beverage *t = new Tea();t->Prepare();cout << "==========Coffe============" << endl;Beverage *c = new Coffe();c->Prepare();return 0;}
0 0
- <Head First 设计模式>:模板方法模式:Beverage
- <Head First 设计模式>:装饰者模式--Beverage
- Head First设计模式-模板方法模式
- 《Head First 设计模式》模板方法模式
- 《Head First 设计模式》之模板方法模式
- 调侃《Head First设计模式》之模板方法模式
- 模板方法模式(Head First设计模式 读书笔记)
- Head First设计模式学习—模板方法、策略模式
- Head First 设计模式之模板方法模式
- 《Head first设计模式》学习笔记 - 模板方法模式
- 《 Head first设计模式 》学习笔记 – 模板方法模式
- Head First 设计模式(八)模板方法模式
- Head First设计模式笔记(模板方法模式)
- Template Method-模板方法模式《Head First 设计模式》
- Head First 设计模式
- Head-first设计模式
- head first 设计模式
- head first 设计模式
- 单例的3种写法
- c++ 覆盖、重载、隐藏
- 对象的内存图
- 新手向!开源播放器JamsMusicPlayer源码解析
- PHP中处理浮点数的一些方法记录
- <Head First 设计模式>:模板方法模式:Beverage
- 我的第一篇博客
- IplImage中的widthStep大小计算及原理
- 黑马程序员_Java基础_多线程
- UIWebView的三种加载方式
- Java读书笔记01 编译和运行Java程序
- 霍纳规则(C/C++,Scheme)
- 2D画图 & CGContextRef 常用的函数和方法
- CGPonit,CGSize,CGRect