网站首页代码,wordpress阅读积分,有什么做调查的网站好,网站策划设计外观模式(Facade)
为系统中的一组接口提供一个一致的界面#xff0c;此模式定义了一个高层接口#xff0c;这个接口使得这一子系统更加容易使用。 #include iostreamusing namespace std;// 四个系统子类
class SubSystemOne
{
public:void MethodOne(){cout 此模式定义了一个高层接口这个接口使得这一子系统更加容易使用。 #include iostreamusing namespace std;// 四个系统子类
class SubSystemOne
{
public:void MethodOne(){cout 子系统方法一 endl;}
};class SubSystemTwo
{
public:void MethodTwo(){cout 子系统方法二 endl;}
};class SubSystemThree
{
public:void MethodThree(){cout 子系统方法三 endl;}
};class SubSystemFour
{
public:void MethodFour(){cout 子系统方法四 endl;}
};// 外观类需要了解所有子系统的方法或属性进行组合以备外界调用
class Facade
{
private:SubSystemOne one;SubSystemTwo two;SubSystemThree three;SubSystemFour four;public:Facade() : one(SubSystemOne()), two(SubSystemTwo()), three(SubSystemThree()), four(SubSystemFour()) {}void MethodA(){cout 方法组A()------ endl;one.MethodOne();two.MethodTwo();four.MethodFour();}void MethodB(){cout 方法组B------ endl;two.MethodTwo();three.MethodThree();}
};// 客户端调用
int main()
{Facade facade Facade();facade.MethodA();facade.MethodB();return 0;
}输出
方法组A()------
子系统方法一
子系统方法二
子系统方法四
方法组B------
子系统方法二
子系统方法三