设计模式-外观模式
来源:互联网 发布:多伦多大学 知乎 编辑:程序博客网 时间:2024/06/08 18:58
外观模式(Facade):为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
比如:投资者之前购买股票,因此需要了解各种股票的信息。现在改为购买基金,就只需要了解一个基金,而不用关心基金中具体有哪些股票·。
UML:
//股票1class Stock1 {public: void Buy() { cout << "买入股票1" << endl; } void Sell() { cout << "卖出股票1" << endl; }};//股票2class Stock2 {public: void Buy() { cout << "买入股票2" << endl; } void Sell() { cout << "卖出股票2" << endl; }};//股票3class Stock3 {public: void Buy() { cout << "买入股票3" << endl; } void Sell() { cout << "卖出股票3" << endl; }};//基金class Fund {private: Stock1 stock1; Stock2 stock2; Stock3 stock3;public: void Buy() { stock1.Buy(); stock2.Buy(); stock3.Buy(); } void Sell() { stock1.Sell(); stock2.Sell(); stock3.Sell(); }};int main(){ Fund fund; fund.Buy(); fund.Sell(); system("pause"); return 0;}
1 0
- 设计模式--外观模式
- 设计模式-外观模式
- 设计模式:外观模式
- 设计模式----外观模式
- 设计模式------外观模式
- 设计模式 外观模式
- 设计模式-【外观模式】
- 设计模式-----外观模式
- 设计模式 - 外观模式
- 设计模式 - 外观模式
- 设计模式- 外观模式
- 设计模式-外观模式
- 设计模式 - 外观模式
- 设计模式-外观模式
- 设计模式 - 外观模式
- 设计模式-外观模式
- 设计模式--外观模式
- 设计模式-外观模式
- JSP标签<c:import>
- PDFview展示本地或网络PDF文件
- 人脸识别之Face++
- 安卓中listview在点击时获取item中的值
- Android反编译之如何将app注入广告
- 设计模式-外观模式
- PreferenceActivity 偏好设置
- jQuery的选择器
- java生成验证码工具类
- 吃货联盟
- jquery datatables自定义返回结果
- leetcode:9. Palindrome Number
- Chrome不支持showModalDialog的解决方案
- 安卓开发去除title的方法