首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

c++ 设计形式之 外观模式

2012-08-16 
c++ 设计模式之 外观模式概念为一系列子系统提供一个统一的接口.外关模式一个高层次的接口使子系统更加容

c++ 设计模式之 外观模式
概念

为一系列子系统提供一个统一的接口.外关模式一个高层次的接口使子系统更加容易的使用.

类图c++ 设计形式之 外观模式

示例代码
#include <iostream>// Subsystem 1class SubSystemOne{public:void MethodOne(){ std::cout << "SubSystem 1" << std::endl; };};// Subsystem 2class SubSystemTwo{public:void MethodTwo(){ std::cout << "SubSystem 2" << std::endl; };};// Subsystem 3 class SubSystemThree{public:void MethodThree(){ std::cout << "SubSystem 3" << std::endl; }};// Facadeclass Facade{public:Facade(){pOne = new SubSystemOne();pTwo = new SubSystemTwo();pThree = new SubSystemThree();}void MethodA(){std::cout << "Facade::MethodA" << std::endl;pOne->MethodOne();pTwo->MethodTwo();}void MethodB(){std::cout << "Facade::MethodB" << std::endl;pTwo->MethodTwo();pThree->MethodThree();}private:SubSystemOne *pOne;SubSystemTwo *pTwo;SubSystemThree *pThree;};int main(){Facade *pFacade = new Facade();pFacade->MethodA();pFacade->MethodB();return 0;}



热点排行