&雪扇 Example 102 UNIVE 6 target DrawingEditor Shape TextView BoundingBox() GetExtent() CreateManipulator() adaptee text Line TextShape BoundingBox() BoundingBox() retum text->GetExtent() CreateManipulator() CreateManipulator() 众 retum new TextManipulator adapter Institute of Computer Software 2022-2-27 Nanjing University
Example 2022-2-27 Institute of Computer Software Nanjing University 6 adapter adaptee target
Applicability Use the Adapter pattern when ▣你想使用一个已经存在的类,而它的接口不符合你 的需求。 口你想创建一个可以复用的类,该类可以与其它不相 关的类或不可预见的类(即那些接口可能不一定兼 容的类)协同工作。 ▣ (仅适用于对象Adapter)你想使用一些已经存在 的类,但是不可能对每一个都进行子类化以匹配它 们的接口。对象适配器可以适配它的父类接口。 Institute of Computer Software 2022-2-27 Nanjing University
Applicability Use the Adapter pattern when 你想使用一个已经存在的类,而它的接口不符合你 的需求。 你想创建一个可以复用的类,该类可以与其它不相 关的类或不可预见的类(即那些接口可能不一定兼 容的类)协同工作。 (仅适用于对象Adapter)你想使用一些已经存在 的类,但是不可能对每一个都进行子类化以匹配它 们的接口。对象适配器可以适配它的父类接口。 2022-2-27 Institute of Computer Software Nanjing University 7
&扇 Structure UNIVE 8 Client Target Adap tee Requesto SpecificRequesto 类适配器 protected or private) Adap ter Requesto o Client Target Adap tee Requesto SpecificRequesto 对象适配器 adaptee Adap ter Requesto adaptee->SpecificR equesto Institute of Computer Software 2022-2-27 Nanjing University
Structure 2022-2-27 Institute of Computer Software Nanjing University 8 类适配器 对象适配器
&扇 Participants 1002 9 Target ▣定义Client使用的与特定领域相关的接口 Client 口与符合Target接口的对象协同 Adaptee 口定义一个已经存在的接口,这个接口需要适配 ▣Adapter 口对Adaptee的接口与Target的接口进行适配 Institute of Computer Software 2022-2-27 Nanjing University
Participants Target 定义Client使用的与特定领域相关的接口 Client 与符合Target接口的对象协同 Adaptee 定义一个已经存在的接口,这个接口需要适配 Adapter 对Adaptee的接口与Target的接口进行适配 2022-2-27 Institute of Computer Software Nanjing University 9
&扇 Collaboration UNIVE 10 Client在Adapter实例上调用一些操作,接着适配 器调用Adaptee的操作实现这个请求。 Sample Code Institute of Computer Software 2022-2-27 Nanjing University
Collaboration Client在Adapter实例上调用一些操作,接着适配 器调用Adaptee的操作实现这个请求。 2022-2-27 Institute of Computer Software Nanjing University 10 Sample Code