//外观模式:给接口提供一致的外观
//当客户需要使用到子系统的多个功能时,客户如果逐个去调用每一个功能会引起较大代码量;
//并存在潜在的错误可能性;
//如果这些功能都位于不同的类中,客户需要去了解每一个类
//解决方法是:为所有类的接口提供一个一致的接口,这一接口提供了所有用户需要的操作;
//通俗理解:木兰从军,需要买各种从军用品如马、马鞍、配剑、靴子等,这些东西都不在同一个店里,从而导致木兰东奔西走;
//现在如果有一家专门的军需用品店,那木兰在这家店里就可以买到所有需要的物品
#include<iostream>
using namespace std;
//功能一
class SubSystemOne{
public:
void methodOne()
{
cout<<"method One"<<endl;
}
};
//功能二
class SubSystemTwo{
public:
void methodTwo()
{
cout<<"method Two"<<endl;
}
};
//功能三
class SubSystemThree{
public:
void methodThree()
{
cout<<"method Three"<<endl;
}
};
//提供一致的功能接口
class Facade{
public:
void methodA()
{
systemOne.methodOne();
systemTwo.methodTwo();
systemThree.methodThree();
cout<<"Three Operation"<<endl;
}
void methodB()
{
systemOne.methodOne();
cout<<"Just one operation"<<endl;
}
private:
SubSystemOne systemOne;
SubSystemTwo systemTwo;
SubSystemThree systemThree;
};
i:nt main()
{
Facade facade;
facade.methodA();
facade.methodB();
return 0;
}