版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 设计模式Design Pattern 设计模式:起源面向对象研究的新领域起 源 设计模式:起源设计模式:起源Gof (Gang Of Four,“四人帮” 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 1 设计模式设计模式:研究现状什么叫 模式? 设计模式的研究现状 Bridge(桥梁 模式案
2、例 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.2 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes
3、 no warranties, express or implied, in this summary. 3 设计原则:组合优先设计原则:组合优先继承 复用的缺点 组合 复用的 优点 组合复用的缺点设计原则:组合优先组合优先 例1:设计原则:组合优先区分“Is-A ”与“Has-A ” 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied
4、, in this summary.4 设计原则:组合优先设计原则:组合优先问 题换一个角度看问题 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.5 Bridge(桥梁 模式 “使变化点和不变点独立开来” “鸟类”和“行为”什么关系?拥有 Bridge(桥梁 模式使用桥梁模式的 效果增加增加增加原
5、有代码不需要改动! 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 6 Bridge(桥梁 模式 Bridge(桥梁 模式 结构 意图 适用性 Bridge(桥梁 模式Bridge(桥梁 模式应用举例 1:“小朋友画画” Bridge(桥梁 模式蜡笔和毛笔的差别体现了Bridge 模式 2003-
6、2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.7 Bridge( 桥梁 模式 分析 设计原则:开 - 闭原则、封装可变性设计原则:开-闭原则、封装可变性“ 开-闭 ”原则Bertrand Meyer 解释 设计原则:开-闭原则、封装可变性设计原则:开-闭原则、封装可变性玉帝遵照 “开-闭”原则维护天庭秩序分
7、析 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 8 设计原则:开-闭原则、封装可变性设计原则:开-闭原则、封装可变性分 析“封装可变性原则” 设计原则:开-闭原则、封装可变性问题 2003-2004 Microsoft Corporation. All rights reserved.This
8、 presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.9 设计原则 策略模式-开闭原则例-计算价格某类方法 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied
9、, in this summary. 10 思考方法n思考方法?n更好的方法?方法n 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.11价格策略销售策略 Strategy(策略 :ConcreteStrategy(具体策略 :Context(上下文 : 阶段小结策略模式桥梁模式 2003-2004
10、 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.12Adapter(适配器 模式 例子2: Adapter(适配器 模式否定 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purp
11、oses only. Microsoft makes no warranties, express or implied, in this summary.13 Adapter(适配器 模式结构Adapter(适配器 模式Adapter(适配器 模式结构意图 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summ
12、ary. 14 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 15 真实世界中的适配器 真实世界中的适配器问题 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational
13、purposes only. Microsoft makes no warranties, express or implied, in this summary. 16 实例 JDBC/ODBC桥梁 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 17 设计原则:里氏代换原则 问 题 设计原则:
14、里氏代换原则错在哪里?墨子论“取譬” 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 18 设计原则:里氏代换原则反过来的代换不成立墨子又说 设计原则:里氏代换原则 用里氏代换原则来判断 设计模式工厂模式 2003-2004 Microsoft Corporation. All rights re
15、served.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.19 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this sum
16、mary. 20 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 21 依赖倒置原则 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only.
17、 Microsoft makes no warranties, express or implied, in this summary. 22遵循倒置依赖原则的指导方针 变量 不可以持有具体类的引用 不要让类派生自具体类不是随时都要遵循这个原则新需求 实现一个原料工厂 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this
18、 summary. 23 比较工厂方法和抽象方法 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 24 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purpo
19、ses only. Microsoft makes no warranties, express or implied, in this summary. 25 设计原则:依赖倒置原则高层依赖低层的问题 设计原则:针对接口编程“针对接口编程”的一些建议当然这些只是建议 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this
20、 summary.26 式Factory Method(工厂方法 模 简单工厂的优缺点优点:缺点: 式Factory Method(工厂方法 模 简单工厂的问题 态来应对 工厂方法:使用多 Factory Method(式工厂方法 模式Factory Method(工厂方法 模结构意图优点 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or impli
21、ed, in this summary. 27 Fa ade(门面 模式例2:组建家庭影院 Fa ade(门面 模式欣赏一部电影的辛苦过程:1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 28 Fa ade( 门面 模式 缺点 设计原则
22、:迪米特法则 老子论“圣人之治”使民无知 老死不相往来 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 29 比较遵守最少知识原则的例子练习练习思考 2003-2004 Microsoft Corporation. All rights reserved.This presentation is
23、for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 30 Fa ade(门面 模式 目的 Fa ade(门面 模式设计原则:迪米特法则Fa ade V.S. Adapter门面模式对迪米特法则的体现 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no
24、 warranties, express or implied, in this summary. 31 设计原则:接口隔离原则接口隔离原则(ISP接口隔离原则和迪米特法则的关系nn也体现了高内聚、低耦合 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 32 ISPnwnww w ww 2003-
25、2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.33Command(命令 模式给家庭影院配一个遥控 器 Command(命令 模式Command(命令 模式结构分析 2003-2004 Microsoft Corporation. All rights reserved.This presentation i
26、s for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.34 Command(命令 模式 分析 Command(命令 模式人物关系 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in
27、 this summary.35 Command(命令 模式效果 Command(命令 模式效果 Command(命令 模式Command(命令 模式结构:分析 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.36 Command(命令 模式Command( 命令 模式应 用举 例2 :“玉帝传美猴
28、王上天”结构 好莱坞法则“Don t call us, well call you” 好莱坞法则回调(Call back) 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.37 遥控器实例 命令模式实现命令接口命令对象使用命令对象 2003-2004 Microsoft Corporation. A
29、ll rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.38 简单测试 实现遥控器 实现遥控器支持撤销 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties
30、, express or implied, in this summary.39 使用宏命令新要求 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 40首先 ,创建想要进入宏的命令集合创建两个命 令数组 命令模式的其他用途将宏命令指定给我们所希望的按钮工作队列日志请求封装目前,已经封装了现在设计模
31、式模版方法模式 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.41背景茶和咖啡的冲泡方法步骤有些是重复的 认识模版方法perpareRecipe(是模版方法 2003-2004 Microsoft Corporation. All rights reserved.This presentation
32、 is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.42 对模版方法进行挂钩 使用钩子 用模版方法排序 Applet 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in th
33、is summary.43 Template Method 模板方法 Template Method 模板方法 意图 设计模式观察者模式一个气象站应用 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.44 在这个实现中 认识观察者模式 报纸和杂志的订阅 Java 内置的观察者模式 2003-2004 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 45 在JDK 中,还有哪些观察者模式 Observer(观察者 模式例子:“网络聊天
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年克孜勒苏职业技术学院单招综合素质考试题库附参考答案详解(基础题)
- 2026年包头轻工职业技术学院单招职业适应性考试题库附答案详解(完整版)
- 2026年保定职业技术学院单招职业适应性测试题库附答案详解(巩固)
- 2026年克孜勒苏职业技术学院单招职业适应性考试题库带答案详解(培优b卷)
- 2026年财务成本管理专业技能测试题
- 2026年旅游管理专业面试题旅游规划目的地管理
- 2026年机械类试题数控编程与操作模拟练习题
- 2026年时尚潮流趋势服装设计流行元素调研模拟试题
- 2026年教师招聘面试题目解析教育教学能力与心理素质考察
- 2026年企业会计财务报表分析与解读技能笔试题目
- 2025及未来5年光学及摄像仪器项目投资价值分析报告
- 第十届“雄鹰杯”小动物医师技能大赛备考试题库(含答案)
- 2026年渭南职业技术学院单招职业技能测试题库必考题
- 2025比亚迪供应商审核自查表
- 精雕铸铝门专业知识培训课件
- DGTJ08-2105-2022 行道树栽植与养护技术标准
- 河北省唐山市二中学2026届中考数学全真模拟试题含解析
- B细胞淋巴瘤课件
- 谷雨生物2024环境、社会及管治(ESG)报告
- 2025金风变流器2.0MW故障代码手册V4
- 房地产估价试题及答案
评论
0/150
提交评论