外观模式(Facade),为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
UML
测试代码
#include <iostream>
using namespace std;class SubSystemOne
{
public:void MethodOne(){cout << "MethodOne" << endl;}
};
class SubSystemTwo
{
public:void MethodTwo(){cout << "MethodTwo" << endl;}
};class SubSystemThree
{
public:void MethodThree(){cout << "MethodThree" << endl;}
};class SubSystemFour
{
public:void MethodFour(){cout << "SubSystemFour" << endl;}
};class Facade
{SubSystemOne one;SubSystemTwo two;SubSystemThree three;SubSystemFour four;
public:void MethodA(){cout << endl << "方法组A()" << endl;one.MethodOne();two.MethodTwo();four.MethodFour();}void MethodB(){cout << endl << "方法组B()" << endl;one.MethodOne();three.MethodThree();four.MethodFour();}
};int main(void)
{Facade f;f.MethodA();f.MethodB();return 0;
}
运行结果
方法组A()
MethodOne
MethodTwo
SubSystemFour方法组B()
MethodOne
MethodThree
SubSystemFour