LoD 102 11 LoD的实质是控制对象之间的信息流量,流向及信 息的影响信息隐藏 在类的划分上,应当创建有弱耦合的类。类之间的耦合 ▣ 越弱,就越有利于复用。 口 在类的结构设计上,每一个类都应当尽量降低成员的访 问权限。一个类不应当public自己的属性,而应当提供 取值和赋值的方法让外界间接访问自己的属性。 口 在类的设计上,只要有可能,一个类应当设计成不变类。 在对其它对象的引用上,一个类对其它对象的引用应该 降到最低。 Institute of Computer Software 2022-2-27 Nanjing University
LoD LoD的实质是控制对象之间的信息流量,流向及信 息的影响 -- 信息隐藏 在类的划分上,应当创建有弱耦合的类。类之间的耦合 越弱,就越有利于复用。 在类的结构设计上,每一个类都应当尽量降低成员的访 问权限。一个类不应当public自己的属性,而应当提供 取值和赋值的方法让外界间接访问自己的属性。 在类的设计上,只要有可能,一个类应当设计成不变类。 在对其它对象的引用上,一个类对其它对象的引用应该 降到最低。 2022-2-27 Institute of Computer Software Nanjing University 11
&扇 OO设计目标与原则 UNIVE 12 o可扩展性(OCP LSP DIP CARP) 口灵活性(OCP,LoD,ISP) 口可插入性(OCP,LSP,CARP,DIP) Institute of Computer Software 2022-2-27 Nanjing University
OO设计目标与原则 可扩展性 (OCP, LSP, DIP, CARP) 灵活性 (OCP, LoD, ISP) 可插入性 (OCP, LSP, CARP, DIP) 2022-2-27 Institute of Computer Software Nanjing University 12
&扇 Principle vs.Pattern 13 口模式都最大化的遵循这些原则 口通过原则、策略“推导”出模式 Institute of Computer Software 2022-2-27 Nanjing University
Principle vs. Pattern 模式都最大化的遵循这些原则 通过原则、策略“推导”出模式 2022-2-27 Institute of Computer Software Nanjing University 13
Design Patterns:Why? 1902 14 直接目的:满足对优秀、简单而且可重用的解 决方案的需要。 口掌握解决反复出现的问题的办法; 口沟通的手段(设计词汇;文档) 更进一步: 口从这些实践证明是成功的设计中学习“设计” ■反复阅读; ■反复应用; ■反复揣摩。 Institute of Computer Software 2022-2-27 Nanjing University
Design Patterns: Why? 直接目的:满足对优秀、简单而且可重用的解 决方案的需要。 掌握解决反复出现的问题的办法; 沟通的手段(设计词汇;文档) 更进一步: 从这些实践证明是成功的设计中学习“设计” 反复阅读; 反复应用; 反复揣摩。 2022-2-27 Institute of Computer Software Nanjing University 14
Design Patterns:What? 102 15 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 2022-2-27 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" 模式是某外在环境下,对特定问题的惯用解决方案 本质上是设计经验的文档化 2022-2-27 Institute of Computer Software Nanjing University 15