ImageVerifierCode 换一换
格式:PPT , 页数:33 ,大小:746.50KB ,
资源ID:7801716      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-7801716.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Design Patterns 1.ppt)为本站会员(hyngb9260)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

Design Patterns 1.ppt

1、Design Patterns - OO design Principle,Foglight Zhuhai Dashboard Team,Agenda,What is Object-oriented design principle Object-oriented design principles Open-Closed Principle (OCP) Single Responsibility Principle (SRP) Liskov Substitution Principle (LSP) Interface Segregation Principle (ISP) Dependenc

2、y Inversion Principle (DIP) References,What is Object-oriented design principle,Object-oriented design is the process of planning a system of interacting objects for the purpose of solving a software problem.The experience and regularity when we use object-oriented design which can help programmer t

3、o create a system that is easy to maintain and extend over time.,Object-oriented design principles(1),Five principles of class design: Open-Closed Principle (OCP: 开合原则) Single Responsibility Principle (SRP: 单职原则) Liskov Substitution Principle (LSP: 里氏置换原则) Interface Segregation Principle (ISP: 接口隔离原

4、则) Dependency Inversion Principle (DIP: 依赖倒置原则),Object-oriented design principles(2),Three principles of package cohesion: Reuse Release Equivalence Principle (REP: 重用发布等价原则) Common Closure Principle (CCP: 公共封闭原则) Common Reuse Principle (CRP: 公共复用原则)Three principles of package coupling : Acyclic Dep

5、endencies Principle (ADP: 无环依赖原则) Stable Dependencies Principle (SDP: 稳定依赖原则) Stable Abstractions Principle (SAP: 稳定抽象原则),Object-oriented design principles,Open-Closed Principle (OCP) Single Responsibility Principle (SRP) Liskov Substitution Principle (LSP) Interface Segregation Principle (ISP) Depe

6、ndency Inversion Principle (DIP),Open-Closed Principle (OCP),Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification Abstraction is the Key Encapsulate the Variation Inheritance and aggregationIs-A VS Has-A,Example violated OCP,class Shapestrin

7、g type (“circle”, “square”, ); Void drawAllShapes(List Shapes)for(Shape shape : Shapes)if(shape.type = “circle”)drawCircle(shape); else if(shape.type = “square”) drawSquare(shape); ,Refactor it to follow OCP,Interface Shapepbulic void draw(); class Circle implements Shape class Square implements Sha

8、pe Void drawAllShapes(List Shapes)for(Shape shape : Shapes)shape.draw(); ,Bad Example in DME project,Get Virtual Machines from Topology Objects,Object-oriented design principles,Open-Closed Principle (OCP) Single Responsibility Principle (SRP) Liskov Substitution Principle (LSP) Interface Segregatio

9、n Principle (ISP) Dependency Inversion Principle (DIP),Single Responsibility Principle (SRP),Every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class A responsibility as a reason to change, and concludes that a class or module should have

10、one, and only one, reason to change,Example violated SRP,Refactor it to follow SRP,Another example about SRP,interface Modem public void dial(String phoneNO);public void hangup();public void send(String c);public String receive(); ,Bad example in DME project,com.quest.dme.capacity.data.DataRetriver,

11、Object-oriented design principles,Open-Closed Principle (OCP) Single Responsibility Principle (SRP) Liskov Substitution Principle (LSP) Interface Segregation Principle (ISP) Dependency Inversion Principle (DIP),Liskov Substitution Principle (LSP),If S is a subtype of T, then objects of type T may be

12、 replaced with objects of type S without altering any of the desirable properties of that. Subtype must be substituted for its base type,Example violated LSP(1),class Rectangle private double width;private double height;void setWidth(double w) width=w;void setHeight(double h) height=h;double getHeig

13、ht() return height;double getWidth() return width; ;class Square extends Rectanglevoid setWidth(double w) super.setWidth(w); super.setHeight(w)void setHeight(double h) super.setWidth(h); super.setHeight(h) ,Example violated LSP(2),double arear.setWidth(5);r.setHeight(4);assert(r.getWidth() * r.getHe

14、ight() = 20); ,How to follow LSP,Contravariance of method arguments in the subtype. Covariance of return types in the subtype. No new exceptions should be thrown by methods of the subtype Preconditions cannot be strengthened in a subtype. Postconditions cannot be weakened in a subtype. Invariants of

15、 the supertype must be preserved in a subtype.,Object-oriented design principles,Open-Closed Principle (OCP) Single Responsibility Principle (SRP) Liskov Substitution Principle (LSP) Interface Segregation Principle (ISP) Dependency Inversion Principle (DIP),Interface Segregation Principle (ISP),Spli

16、ts too large interfaces into smaller and more specific ones so that any client it will only know about the methods that are of interest. No client should be forced to depend on methods it does not use. Separate Clients mean Separate Interfaces,ATM Example violated ISP,Refactor it to follow ISP,Bad e

17、xample in DME project,com.quest.dme.hyperv.capacity.calculator.retriever.DataRetriver,Object-oriented design principles,Open-Closed Principle (OCP) Single Responsibility Principle (SRP) Liskov Substitution Principle (LSP) Interface Segregation Principle (ISP) Dependency Inversion Principle (DIP),Dep

18、endency Inversion Principle (DIP),A. High-level modules should not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend upon details. Details should depend upon abstractions.,Example violated DIP,Refactor it to follow DIP,How to follow DIP,Any variable s

19、hould not hold a reference point to the specific class. Any class should not be derived from the concrete class. Any method should not override the method which has already been implemented in base class.,Bad example in DME project,com.quest.dme.scan.model.action.Action,References,Agile Software Development, Principles, Patterns, and Practices (敏捷软件开发:原则、模式与实践) Design Patterns: Elements of Reusable Object-Oriented Software(设计模式-可复用面向对象软件的基础) Head First Design Patterns(深入浅出设计模式) Java与模式 Google zhu13916technology documentdesign patterns,

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报