c++建造者模式
来源:互联网 发布:找房子软件 编辑:程序博客网 时间:2024/05/12 12:07
// ConsoleApplication1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>//#include "Factory.h"using namespace std;class Man{public: Man():flag(false) {} void BuildHead() {cout<<"Head is building"<<endl;} void BuildBody() { flag = true;//body is finished,so man is OK; cout<<"Body is building"<<endl; } void ShowResult() { if(flag) { cout<<"Man was OK"<<endl; } else { cout<<"Man was not OK"<<endl; } }private: bool flag;};class Builder{public: virtual void BuildHead() = 0; virtual void BuildBody() = 0; virtual Man* GetMan() const = 0;};class ChineseBuilder:public Builder{private: Man* m_pMan;public: ChineseBuilder():m_pMan(new Man()) {} void BuildHead() {m_pMan->BuildHead();} void BuildBody() {m_pMan->BuildBody();} Man* GetMan() const {return m_pMan;}};class Director{public: Director(Builder* pMan) {m_pMan = pMan;} void CreateMan() { if(NULL != m_pMan) { m_pMan->BuildHead(); m_pMan->BuildBody(); } }private: Builder* m_pMan;};int _tmain(int argc, _TCHAR* argv[]){ // you need to build a man ,and you he must be Chinese. Builder* pBuilder = new ChineseBuilder(); // OK,we know you need to build a Chinese man. Director* pDirector = new Director(pBuilder); // begin to build a man . pDirector->CreateMan(); Man* pMan = pBuilder->GetMan(); // check whether we have built the Chinese succeed. pMan->ShowResult(); getchar(); return 0;}
0 0
- 【C++】Chapter9:建造者模式
- Objective C--建造者模式
- Objective C 建造者模式
- Objective C--建造者模式
- 建造者模式(C++)
- C#--设计模式之建造者模式
- 乐在其中设计模式(C#) - 建造者模式(Builder Pattern)
- C语言和设计模式(建造者模式)
- C语言和设计模式(建造者模式)
- C语言和设计模式(建造者模式)
- 09.C语言和设计模式(建造者模式)
- 18、C语言和设计模式(建造者模式)
- 设计模式c++(二)----Biluder建造者模式
- 建造模式C语言实现
- Builder 建造者模式
- 建造者模式
- 设计模式-------建造者
- 建造者模式
- iOS国际化
- 数据库锁
- CCRenderBuffer初始化中的render state参数
- spring mvc使用@InitBinder 标签对表单数据绑定
- 日经春秋 20151004
- c++建造者模式
- 判断请求时手机端访问还是电脑端访问
- javaWeb中解决中文乱码问题
- hdu1024Max Sum Plus Plus【状态dp 滚动数组】
- 使用Linux的sar 命令来计算Linux的内存剩余
- 黑马程序员——Java基础(六)之常用类
- UITabBarController
- android Jsoup获取网站内容(实例为新闻标题获取),android网络必学
- lambda表达式,结合map、reduce、filter函数