外观模式
外观模式是一个子系统的封装,通过访问外观来实现访问子系统。只要定义好了这个接口,来创造出新的子系统是非常容易。
#include <iostream>
using namespace std;
class fact_one
{
public:
void sell(){
cout<<"sell fact_one"<<endl;
}
void buy(){
cout<<"buy fact_one"<<endl;
}
};
class fact_two
{
public:
void sell(){
cout<<"sell fact_two"<<endl;
}
void buy(){
cout<<"buy fact_two"<<endl;
}
};
class lead
{
public:
lead(){
one = new fact_one();
two = new fact_two();
}
void sell(){
one->sell();
two->sell();
}
void buy(){
one->buy();
two->buy();
}
private:
fact_one *one;
fact_two *two;
};
int main(int argc, char *argv[])
{
lead *leader = new lead();
leader->sell();
return 0;
}