设计模式 -------------------外观模式
2015-06-25 13:10
417 查看
外观模式的优点:
为子系统的一组接口提供一个一直的界面 ,让用户使用起来更加方便。
结构图如下:
具体使用代码如下:
// Strategy.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class SubClassOne{
public:
void MedthodOne(){
cout << "方法一" << endl;
}
};
class SubClassTwo{
public:
void MedthodTwo(){
cout << "方法二" << endl;
}
};
class SubClassThree{
public:
void MedthodThree(){
cout << "方法三" << endl;
}
};
//外观类
class Fachade{
private:
SubClassOne * sub1;
SubClassTwo *sub2;
SubClassThree *sub3;
public:
Fachade(){
sub1 = new SubClassOne;
sub2 = new SubClassTwo;
sub3 = new SubClassThree;
}
~Fachade(){
delete sub1;
delete sub2;
delete sub3;
}
void FachadeMethod(){
sub1->MedthodOne();
sub2->MedthodTwo();
sub3->MedthodThree();
}
};
int main(){
Fachade* test = new Fachade;
test->FachadeMethod();
getchar();
getchar();
return 0;
}
为子系统的一组接口提供一个一直的界面 ,让用户使用起来更加方便。
结构图如下:
具体使用代码如下:
// Strategy.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class SubClassOne{
public:
void MedthodOne(){
cout << "方法一" << endl;
}
};
class SubClassTwo{
public:
void MedthodTwo(){
cout << "方法二" << endl;
}
};
class SubClassThree{
public:
void MedthodThree(){
cout << "方法三" << endl;
}
};
//外观类
class Fachade{
private:
SubClassOne * sub1;
SubClassTwo *sub2;
SubClassThree *sub3;
public:
Fachade(){
sub1 = new SubClassOne;
sub2 = new SubClassTwo;
sub3 = new SubClassThree;
}
~Fachade(){
delete sub1;
delete sub2;
delete sub3;
}
void FachadeMethod(){
sub1->MedthodOne();
sub2->MedthodTwo();
sub3->MedthodThree();
}
};
int main(){
Fachade* test = new Fachade;
test->FachadeMethod();
getchar();
getchar();
return 0;
}
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- PropertyChangeListener简单理解
- 关于指针的一些事情
- 什么是设计模式
- 设计模式之创建型模式 - 特别的变量问题
- 设计模式之创建型模式
- 浅谈设计模式的学习
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++编写简单的打靶游戏
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解