设计模式---外观模式 实例
2015-05-28 12:55
337 查看
代码:
#include <iostream>
using namespace std;
class stock
{
public:
virtual void sell() = 0;
virtual void buy() = 0;
};
class stock1 : public stock
{
public:
void sell()
{
cout<<"stock1 sell"<<"\n";
}
void buy()
{
cout<<"stock1 buy"<<"\n";
}
};
class stock2 : public stock
{
public:
void sell()
{
cout<<"stock2 sell"<<"\n";
}
void buy()
{
cout<<"stock2 buy"<<"\n";
}
};
class fund
{
private:
stock1 gp1;
stock2 gp2;
public:
void sellFund()
{
gp1.sell();
gp2.sell();
}
void buyFund()
{
gp1.buy();
gp2.buy();
}
};
int main()
{
fund jijin;
jijin.buyFund();
jijin.sellFund();
return 0;
}
运行结果:
ngnsvr9 [** NONE **]/home/xionghailong/demo/facade $ g++ main.cpp -o main
ngnsvr9 [** NONE **]/home/xionghailong/demo/facade $ ./main
stock1 buy
stock2 buy
stock1 sell
stock2 sell
#include <iostream>
using namespace std;
class stock
{
public:
virtual void sell() = 0;
virtual void buy() = 0;
};
class stock1 : public stock
{
public:
void sell()
{
cout<<"stock1 sell"<<"\n";
}
void buy()
{
cout<<"stock1 buy"<<"\n";
}
};
class stock2 : public stock
{
public:
void sell()
{
cout<<"stock2 sell"<<"\n";
}
void buy()
{
cout<<"stock2 buy"<<"\n";
}
};
class fund
{
private:
stock1 gp1;
stock2 gp2;
public:
void sellFund()
{
gp1.sell();
gp2.sell();
}
void buyFund()
{
gp1.buy();
gp2.buy();
}
};
int main()
{
fund jijin;
jijin.buyFund();
jijin.sellFund();
return 0;
}
运行结果:
ngnsvr9 [** NONE **]/home/xionghailong/demo/facade $ g++ main.cpp -o main
ngnsvr9 [** NONE **]/home/xionghailong/demo/facade $ ./main
stock1 buy
stock2 buy
stock1 sell
stock2 sell
相关文章推荐
- 23种设计模式C++实例之外观模式
- Net设计模式实例之外观模式(Façade Pattern)
- Net设计模式实例之外观模式(Façade Pattern)
- 【翻译】设计模式之外观(Facade)模式——C++实例
- 设计模式--原型/外观(OC 实例)
- Net设计模式实例之外观模式(Façade Pattern)(1) 推荐
- Net设计模式实例之外观模式(Façade Pattern)(2)
- 实例解析设计模式中的外观模式在iOS App开发中的运用
- 结合项目实例 回顾传统设计模式(七)适配器模式(附外观模式)
- Net设计模式实例之外观模式(Façade Pattern)
- 设计模式之外观模式实例
- 结合项目实例 回顾传统设计模式(七)适配器模式(附外观模式)
- Java设计设计模式之外观模式(Facade)
- 设计模式--适配器模式、外观模式
- 设计模式之Facade(外观 总管 Manager)
- 设计模式之外观模式(C++实现)
- Java 设计模式_外观设计(简单了解)
- IOS 设计模式之外观(比较容易理解)
- 【设计模式】牛市股票还会亏钱 --- 外观模式
- 设计模式(17)-----外观设计模式