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

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

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

Design Pattern(3) 设计模式(3 Institute of Computer Software 2021/2/5 Nanjing University

设计模式(3) Design Pattern (3) 2021/2/5 Institute of Computer Software Nanjing University 1

最病 过摘要 2 Design Patterns a Why, What, How a Creational, Structural and Behavioral Patterns Institute of Computer Software 2021/215 Nanjing University

摘要  Design Patterns  Why, What, How  Creational, Structural and Behavioral Patterns 2021/2/5 Institute of Computer Software Nanjing University 2

最病 A Behavioral Patterns 口行为模式是对在不同的对象之间划分责任和算 法的抽象化。行为模式不仅仅是关于类和对象 的,而且关注它们之间的通信模式。 口类的行为模式:使用继承关系在几个类之间分配行 *-Interpreter template Method 口对象的行为模式:使用对象的聚合来分配行为 Institute of Computer Software 2021/215 Nanjing University

Behavioral Patterns  行为模式是对在不同的对象之间划分责任和算 法的抽象化。行为模式不仅仅是关于类和对象 的,而且关注它们之间的通信模式。  类的行为模式:使用继承关系在几个类之间分配行 为 – Interpreter, Template Method  对象的行为模式:使用对象的聚合来分配行为 2021/2/5 Institute of Computer Software Nanjing University 3

最病 A Behavioral Patterns a Chain of responsibility 口 Command 口 Interpreter 口| terator 口 Mediator 口 Memento 口○ oserver a State 口 Strategy 口 Template Method 口 Visitor Institute of Computer Software 2021/215 Nanjing University

Behavioral Patterns  Chain of Responsibility  Command  Interpreter  Iterator  Mediator  Memento  Observer  State  Strategy  Template Method  Visitor 2021/2/5 Institute of Computer Software Nanjing University 4

最病 A Chain of Responsibility 5 口| ntent 口使多个对象都有机会处理请求,从而避免请求的发送者和接 收者之间的耦合关系。将这些对象连成一条链,并沿着这条 链传递该请求,直到有一个对象处理它为止。 口 Motivation 口应根据普遍性即从最特殊到最普遍的顺序来组织帮助信息 比如用户界面中会有一个对象来处理帮助请求,但是哪一个 对象则取决于上下文 口给多个对象处理一个请求的机会,从而解耦发送者和接受者 Institute of Computer Software 2021/215 Nanjing University

Chain of Responsibility  Intent  使多个对象都有机会处理请求,从而避免请求的发送者和接 收者之间的耦合关系。将这些对象连成一条链,并沿着这条 链传递该请求,直到有一个对象处理它为止。  Motivation  应根据普遍性即从最特殊到最普遍的顺序来组织帮助信息, 比如用户界面中会有一个对象来处理帮助请求,但是哪一个 对象则取决于上下文  给多个对象处理一个请求的机会,从而解耦发送者和接受者 2021/2/5 Institute of Computer Software Nanjing University 5

最病 Exampl e 6 asaveDlalog handler aPrntButton anApplleatilon handler handler aPrintDlalog handler anoKButton handler specific aPrintButton aPrintDialog anApplication HandleHelpO HandleHelpo Institute of Computer Software 2021/215 Nanjing University

Example 2021/2/5 Institute of Computer Software Nanjing University 6

最病 E Applicability 7 口有多个对象可以处理一个请求,哪个对象处理 该请求则在运行时刻确定 口在不明确指定接收者的情况下,向多个对象中 的一个提交一个请求 口可处理一个请求的对象集合应被动态制定 Institute of Computer Software 2021/215 Nanjing University

Applicability  有多个对象可以处理一个请求,哪个对象处理 该请求则在运行时刻确定  在不明确指定接收者的情况下,向多个对象中 的一个提交一个请求  可处理一个请求的对象集合应被动态制定 2021/2/5 Institute of Computer Software Nanjing University 7

最病 o Structure 8 SUccessor Clent Handker HandleRequesto c。 ncreteHandler Concretehandlen HandleRequesto Handle Request Institute of Computer Software 2021/215 Nanjing University

Structure 2021/2/5 Institute of Computer Software Nanjing University 8

最病 A Participants 9 口Hand|er 口定义一个处理请求的接口 口(可选)实现后继链 口 Concretehand|er 口处理它所负责的请求 口可访问它的后继者 口如果可处理该请求,就处理之;否则将该请求转发给它的后 继者 a Client 口提交请求 Institute of Computer Software 2021/215 Nanjing University

Participants  Handler  定义一个处理请求的接口  (可选)实现后继链  ConcreteHandler  处理它所负责的请求  可访问它的后继者  如果可处理该请求,就处理之;否则将该请求转发给它的后 继者  Client  提交请求 2021/2/5 Institute of Computer Software Nanjing University 9

最病 Collaboration 口当 Client提交一个请求时,请求沿链传递直至有 个 Concretehandler对象负责处理它 a client aConcreteHandler cHandler aConcreteHandler successor successor Sample Code Institute of Computer Software 2021/215 Nanjing University

Collaboration  当Client提交一个请求时,请求沿链传递直至有 一个ConcreteHandler对象负责处理它 2021/2/5 Institute of Computer Software Nanjing University 10 Sample Code

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

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

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