您的位置:首页 > 编程语言 > C语言/C++

设计模式之外观模式 c++实现

2014-07-05 21:39 465 查看
外观模式:

                 外观模式指为子系统的一组接口提供一个一致的画面,为此模式定义了一个高层接口,这个接口使得这一系统更加容易使用。

UML图:

                              


演示程序: 

#include<iostream>
using namespace std;
/******************************************
* 外观模式演示程序 *
* by hnust_xiehonghao *
* 2014.7.5 *
******************************************/
class CPU
{
public:
void state()
{
printf("Cpu初始化...\n");
}
};

class Memory
{
public:
void state()
{
printf("Memory初始化...\n");
}
};

class HardDriver
{
public:
void state()
{
printf("HardDrive初始化...\n");
}
};

class Computer
{
public:
Computer()
{
pCpu = new CPU;
pMemory = new Memory;
pHardDriver = new HardDriver;
}
void Start()
{
pCpu->state();
pMemory->state();
pHardDriver->state();
}
private :
CPU *pCpu;
Memory *pMemory;
HardDriver *pHardDriver;
~Computer()
{
delete pCpu;
delete pMemory;
delete pHardDriver;
}
};

int main()
{
Computer *pComputer;
pComputer = new Computer;
pComputer->Start();
return 0;
}

    
                    


 

参考: 

         大话设计模式
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: