用網(wǎng)站做淘客怎么做株洲seo優(yōu)化推薦
外觀模式(Facade)
為系統(tǒng)中的一組接口提供一個(gè)一致的界面,此模式定義了一個(gè)高層接口,這個(gè)接口使得這一子系統(tǒng)更加容易使用。
#include <iostream>using namespace std;// 四個(gè)系統(tǒng)子類
class SubSystemOne
{
public:void MethodOne(){cout << "子系統(tǒng)方法一" << endl;}
};class SubSystemTwo
{
public:void MethodTwo(){cout << "子系統(tǒng)方法二" << endl;}
};class SubSystemThree
{
public:void MethodThree(){cout << "子系統(tǒng)方法三" << endl;}
};class SubSystemFour
{
public:void MethodFour(){cout << "子系統(tǒng)方法四" << endl;}
};// 外觀類,需要了解所有子系統(tǒng)的方法或?qū)傩?#xff0c;進(jìn)行組合,以備外界調(diào)用
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();}
};// 客戶端調(diào)用
int main()
{Facade facade = Facade();facade.MethodA();facade.MethodB();return 0;
}
輸出:
方法組A()------
子系統(tǒng)方法一
子系統(tǒng)方法二
子系統(tǒng)方法四
方法組B()------
子系統(tǒng)方法二
子系統(tǒng)方法三