当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)12 设计模式 Design Patterns(2)

资源类别:文库,文档格式:PPT,文档页数:79,文件大小:1.78MB,团购合买
Design Patterns  Why, What, How  Creational, Structural and Behavioral Patterns
点击下载完整版文档(PPT)

Design Pattern (2) 设计模式(2) Institute of Computer Software 2022-2-27 Nanjing University

设计模式(2) Design Pattern (2) 2022-2-27 Institute of Computer Software Nanjing University 1

&雪扇 摘要 UNIVE 2 Design Patterns ▣Why,What,How Creational,Structural and Behavioral Patterns Institute of Computer Software 2022-2-27 Nanjing University

摘要  Design Patterns  Why, What, How  Creational, Structural and Behavioral Patterns 2022-2-27 Institute of Computer Software Nanjing University 2

Structural Patterns 3 结构模式描述如何将类或者对象结合在一起形 成更大的结构。 口类的结构模式:结构型类模式使用继承机制来组合 接口或实现。 口对象的结构模式:结构型对象模式描述了如何对一 些对象进行组合,从而实现新功能的一些方法。可 以在运行时刻改变对象组合关系。 Institute of Computer Software 2022-2-27 Nanjing University

Structural Patterns  结构模式描述如何将类或者对象结合在一起形 成更大的结构。  类的结构模式:结构型类模式使用继承机制来组合 接口或实现。  对象的结构模式:结构型对象模式描述了如何对一 些对象进行组合,从而实现新功能的一些方法。可 以在运行时刻改变对象组合关系。 2022-2-27 Institute of Computer Software Nanjing University 3

&雪扇 Structural Patterns 0o2 UNIVE 4 Adapter Bridge Composite Decorator Facade Flyweight Proxy Institute of Computer Software 2022-2-27 Nanjing University

Structural Patterns  Adapter  Bridge  Composite  Decorator  Facade  Flyweight  Proxy 2022-2-27 Institute of Computer Software Nanjing University 4

般感 Adapter 5 Aliases:Wrapper Intent 口将一个类的接口转换成客户希望的另外一个接口。 Adapter模式使得原本由于接口不兼容而不能一起 工作的那些类可以一起工作 Motivation ▣有时为复用而设计的工具箱类不能够被复用的原因 仅仅是因为它的接口与专业应用领域所需要的接口 不匹配 Institute of Computer Software 2022-2-27 Nanjing University

Adapter  Aliases:Wrapper  Intent  将一个类的接口转换成客户希望的另外一个接口。 Adapter模式使得原本由于接口不兼容而不能一起 工作的那些类可以一起工作  Motivation  有时为复用而设计的工具箱类不能够被复用的原因 仅仅是因为它的接口与专业应用领域所需要的接口 不匹配 2022-2-27 Institute of Computer Software Nanjing University 5

&雪扇 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

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共79页,可试读20页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有