最病 A LoD 口LoD的实质是控制对象之间的信息流量,流向及信 息的影响--信息隐藏 口在类的划分上,应当创建有弱耦合的类。类之间的耦合 越弱,就越有利于复用。 口在类的结构设计上,每一个类都应当尽量降低成员的访 问权限。一个类不应当 public自己的属性,而应当提供 取值和赋值的方法让外界间接访问自己的属性。 口在类的设计上,只要有可能,一个类应当设计成不变类。 口在对其它对象的引用上,一个类对其它对象的引用应该 降到最低。 Institute of Computer Software 2021/2/5 Nanjing University
LoD LoD的实质是控制对象之间的信息流量,流向及信 息的影响 -- 信息隐藏 在类的划分上,应当创建有弱耦合的类。类之间的耦合 越弱,就越有利于复用。 在类的结构设计上,每一个类都应当尽量降低成员的访 问权限。一个类不应当public自己的属性,而应当提供 取值和赋值的方法让外界间接访问自己的属性。 在类的设计上,只要有可能,一个类应当设计成不变类。 在对其它对象的引用上,一个类对其它对象的引用应该 降到最低。 2021/2/5 Institute of Computer Software Nanjing University 11
划O设计目标与原则 口可扩展性( OCP LSF,D|P,CARP) 口灵活性(○CP,LoD,|SP 口可插入性(○CP,LSP, CARP D|P) Institute of Computer Software 2021/2/5 Nanjing University
OO设计目标与原则 可扩展性 (OCP, LSP, DIP, CARP) 灵活性 (OCP, LoD, ISP) 可插入性 (OCP, LSP, CARP, DIP) 2021/2/5 Institute of Computer Software Nanjing University 12
最病 A Principle vs Pattern 口模式都最大化的遵循这些原则 口通过原则、策咯“推导”出模式 Institute of Computer Software 2021/2/5 Nanjing Universit
Principle vs. Pattern 模式都最大化的遵循这些原则 通过原则、策略“推导”出模式 2021/2/5 Institute of Computer Software Nanjing University 13
最病 A Design Patterns: Why? 口直接目的:满足对优秀、简单而且可重用的解 决方案的需要。 口掌握解决反复出现的问题的办法; 口沟通的手段(设计词汇;文档) 口更进一步: 口从这些实践证明是成功的设计中学习“设计” ■反复阅读; 反复应用; ■反复揣摩。 Institute of Computer Software 2021/2/5 Nanjing University
Design Patterns: Why? 直接目的:满足对优秀、简单而且可重用的解 决方案的需要。 掌握解决反复出现的问题的办法; 沟通的手段(设计词汇;文档) 更进一步: 从这些实践证明是成功的设计中学习“设计” ◼ 反复阅读; ◼ 反复应用; ◼ 反复揣摩。 2021/2/5 Institute of Computer Software Nanjing University 14
最病 Design Patterns: What? Christopher Alexander《 A Pattern Language》: Each pattern describes a problem which occurs over and over again in our environment and then describes the core of the solution to that problem in such a way that you can use this solution a million times over without ever doing it the same way twice 模式是某外在环境下,对特定问题的惯用解决方案 本质上是设计经验的文档化 Institute of Computer Software 2021/2/5 Nanjing University
Design Patterns: What? Christopher Alexander 《A Pattern Language》: "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice" 模式是某外在环境下,对特定问题的惯用解决方案 本质上是设计经验的文档化 2021/2/5 Institute of Computer Software Nanjing University 15