一、外观模式
1-1、意图
为子系统中的一组接口提供一个一致的界面。
Facade 模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。
1-2、结构

- Facade 知道哪些子系统类负责处理请求:将客户的请求代理给适当的子系统对象。
- Subsvstem classes 实现子系统的功能:处理有 Facade 对象指派的任务:没有 Facade 的任何相关信息,即没有指向 Facade 的指针。
1-3、代码实现



1-4、适用性
- 要为一个复杂子系统提供一个简单接口时,子系统往往因为不断演化而变得越来越复杂。大多数模式使用时都会产生更多更小的类,这使得子系统更具有可重用性,也更容易对子系统进行定制,但也给那些不需要定制子系统的用户带来一些使用上的困难Facade 可以提供一个简单的默认视图,这一视图对大多数用户来说已经足够,而那些需要更多的可定制性的用户可以越过 Facade 层。
- 客户程序与抽象类的实现部分之间存在着很大的依赖性。引入 Facade 将这个子系统与客户以及其他的子系统分离,可以提高子系统的独立性和可移植性。
- 当需要构建一个层次结构的子系统时,使用 Facade 模式定义子系统中每层的入口点。如果子系统之间是相互依赖的,则可以让它们仅通过 Facade 进行通信,从而简化了它们之间的依赖关系。
1-5、真题
真题1:

真题2:

二、享元模式
2-1、意图
运用共享技术有效地支持大量细粒度的对象。
2-2、结构


2-3、适用性
- 应用程序使用了大量的对象。
- 完全由于使用大量的对象,造成很大的存储开销。
- 对象的大多数状态都可变为外部状态。
- 如果删除对象的外部状态,那么可以用相对较少的共享对象取代很多组对象。
- 应用程序不依赖于对象标识。由于 Flyweight 对象可以被共享,所以对于概念上明显有别的对象,标识测试将返回真值。

2-4、代码实现




2-5、真题
真题1:

三、代理模式
3-1、意图
为其他对象提供一种代理以控制对这个对象的访问。
3-2、结构


3-3、代码实现




1-4、适用性

1-5、真题
真题1: