一、适配器模式
1-1、意图
个类的接口转换成客户希望的另外一个接口。
Adapter 模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
1-2、结构
适配器模式分为:
1、适配器类模式;
2、适配器对象模式
类适配器使用多重继承对一个接口与另一个接口进行匹配:

java没有多重继承,所以,类适配器模式,不考。
对象适配器依赖于对象组合:

- Target 定义 Client 使用的与特定领域相关的接口;
- Client 与符合 Target 接口的对象协同;
- Adaptee 定义一个已经存在的接口,这个接口需要适配;(适配器)
- Adapter 对 Adaptee 的接口与 Target 接口进行适配。

1-3、代码实现

客户端:

1-4、适用性
1、想使用一个已经存在的类,而它的接口不符合要求。
2、想创建一个可以服用的类,该类可以与其他不相关的类或不可预见的类(即那些接口可能不一定兼容的类) 协同工作。
3、(仅适用于对象 Adapter)想使用一个已经存在的子类,但是不可能对每一个都进行子类化以匹配它们的接口。对象适配器可以适配它的父类接口。
1-5、真题
真题1:

二、桥接模式
2-1、意图
将抽象部分与其实现部分分离,使它们都可以独立地变化。
2-2、结构

- Abstraction 定义抽象类的接口,维护一个指向 Implementor 类型对象的指针;
- RefinedAbstraction 扩充由 Abstraction 定义的接口。
- Implementor 定义实现类的接口,该接口不一定要与 Abstraction 的接口完全一致;事实上这两个接口可以完全不同。一般来说,Implementor 接口仅提供基本操作,而Abstraction 定义了基于这些基本操作的较高层次的操作。
- Concretelmplementor 实现 Implementor 接口并定义它的具体实现。

1-3、代码实现




1-4、适用性

1-5、真题
真题1:

真题2:45:A

Abstraction 定义抽象类的接口,维护一个指向 Implementor 类型对象的指针。
真题3:
