文档章节

Builder模式

Ne0o0
 Ne0o0
发布于 2017/04/20 17:46
字数 121
阅读 4
收藏 0
class IBuilder
{
public:
	IBuilder(){}
	virtual ~IBuilder(){}
	virtual   void  BuilderPartA()  =   0 ;
	virtual   void  BuilderPartB()  =   0 ;
};

class Director
{
public:
	Director(IBuilder * pBuilter){m_pBuilter=pBuilter;}
	virtual~Director(){}
public:
	void Construct()
	{
		m_pBuilter->BuilderPartA();
		m_pBuilter->BuilderPartB();
	}
private:
	IBuilder *m_pBuilter;
};

class Builder1:public IBuilder
{
public:
	Builder1(){}
	~Builder1(){}
public:
	   void  BuilderPartA(){printf("this is Builder1 A\n");}
	   void  BuilderPartB(){printf("this is Builder1 B\n");}
};

class Builder2:public IBuilder
{
public:
	Builder2(){}
	~Builder2(){}
public:
	void  BuilderPartA(){printf("this is Builder2 A\n");}
	void  BuilderPartB(){printf("this is Builder2 B\n");}
};
int _tmain(int argc, _TCHAR* argv[])
{
	IBuilder *pBuilder1=new Builder1;
	Director director(pBuilder1);
	director.Construct();
	delete pBuilder1;
	IBuilder *pBuilder2=new Builder2;
	Director director(pBuilder2);
	director.Construct();
	delete pBuilder2;
	getchar();
	return 0;
}

© 著作权归作者所有

上一篇: Prototype模式
下一篇: 抽象工厂模式
Ne0o0
粉丝 2
博文 70
码字总数 29011
作品 0
程序员
私信 提问

暂无文章

聊聊Elasticsearch的CircuitBreakerService

序 本文主要研究一下Elasticsearch的CircuitBreakerService CircuitBreakerService elasticsearch-7.0.1/server/src/main/java/org/elasticsearch/indices/breaker/CircuitBreakerService.ja......

go4it
11分钟前
1
0
Spring系列教程六:AOP详细讲解

AOP 概述 什么是 AOP AOP:全称是 Aspect Oriented Programming 即:面向切面编程。 AOP技术是对OOP技术的一种延伸,AOP是面向纵向,OOP是面向横向。简单的说它就是把我们程序重复的代码抽取...

我叫小糖主
25分钟前
9
0
Qt编写数据可视化大屏界面电子看板9-曲线效果

一、前言 为了编写数据可视化大屏界面电子看板系统,为了能够兼容Qt4和嵌入式linux系统,尤其是那种主频很低的,但是老板又需要在这种硬件上(比如树莓派、香橙派、全志H3、imx6)展示这么华...

飞扬青云
46分钟前
3
0
责任链模式

//这篇博客的博主真的不错,解析的都很清晰明了, https://blog.csdn.net/jason0539/article/details/45091639

南桥北木
今天
3
0
Flutter -------- dio网络请求

dio是Flutter中文网开源的一个强大的Dart Http请求库,支持Restful API、FormData、拦截器、请求取消、Cookie管理、文件上传/下载、超时等... 1.添加依赖# dependencies: dio: 2.1.x #...

切切歆语
今天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部