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

来源:互联网 发布:java socket 连接超时 编辑:程序博客网 时间:2024/06/01 17:49

概念

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

类图


示例代码

#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;}



原创粉丝点击