[结构型] -- 外观模式
2012-03-19 18:28
225 查看
外观模式的提出:
为复杂的子系统调用提供一个统一的入口,使子系统与客户的耦合度降低,且客户端调用非常方便。
就像在网站浏览时,开发者为我们设定的主页一样。这样我们就无需去记住所有的子网页的URL,只需要记得主页的URL。这样我们同样可以访问该网站的所有资源,而且还无需记得那么多复杂的URL。两者的道理是一样的。
View Code
为复杂的子系统调用提供一个统一的入口,使子系统与客户的耦合度降低,且客户端调用非常方便。
就像在网站浏览时,开发者为我们设定的主页一样。这样我们就无需去记住所有的子网页的URL,只需要记得主页的URL。这样我们同样可以访问该网站的所有资源,而且还无需记得那么多复杂的URL。两者的道理是一样的。
View Code
#include <iostream> #include <string> using namespace std; // 外观模式 class Light { public: void on() { cout << "灯开了..." << endl; } }; class TV { public: void play() { cout << "电视机播放中..." <<endl; } }; class AirConditioner { public: void on() { cout << "空调开了..." << endl; } }; class Facade // 外观类 { private: Light light; TV t; AirConditioner air; public: Facade(Light &l,TV &tv,AirConditioner &ac) { this->light = l; this->t = tv; this->air = ac; } void LightOn() { this->light.on(); } void TVPlay() { this->t.play(); } void AitConditionerOn() { this->air.on(); } }; void main() { Light l; TV tv; AirConditioner ac; Facade f(l,tv,ac); f.LightOn(); f.TVPlay(); f.AitConditionerOn(); }
相关文章推荐
- [设计模式笔记]二. 结构型模式--11.Facade模式(外观模式)(一)
- java设计模式(结构型)之外观模式
- 设计模式(结构型模式) ----- 外观模式
- Java常用的设计模式12:常用设计模式之外观模式(结构型模式)
- "围观"设计模式(30)--结构型设计模式总结(适配器、代理、装饰、外观、桥梁、组合、享元)
- 设计模式(九)外观模式Facade(结构型)
- 结构型设计模式-外观模式
- 设计模式学习之路——Facade 外观模式(结构型模式)
- 结构型模式之外观模式
- “设计模式”学习之五:桥接、外观、享元与代理(结构型)
- 设计模式11——结构型模式之外观模式
- 外观模式(Facade Pattern)-结构型模式
- 七个结构型模式5:外观模式-Facade Pattern【学习难度:★☆☆☆☆,使用频率:★★★★★】
- 设计模式(九)外观模式Facade(结构型)
- 二十三种设计模式之结构型模式之外观模式
- Façade外观(结构型模式)
- Java设计模式概述之结构型模式(外观模式)
- 外观模式Facade(结构型)
- 【设计模式基础】结构型模式 - 2 - 外观(Facade)
- 门面模式(Facade 外观模式,对象结构型模式)