




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Software Design Principle An Introduction Part Two Dr. ZHOU Xiao-cong Department of Computer Science SUN YAT-SEN UNIVERSITY, GZ 510275,Introduction Single Responsibility Principle (SRP) Open Closed Principle (OCP) Liskov Substitution Principle (LSP) Dependency Inversion Principle (DIP) Interface Seg
2、regation Principle (ISP) Least Knowledge Principle (LKP),Software Design Principle,Introduction Single Responsibility Principle (SRP) Open Closed Principle (OCP) Liskov Substitution Principle (LSP) Dependency Inversion Principle (DIP) Interface Segregation Principle (ISP) Least Knowledge Principle (
3、LKP),Software Design Principle,Barbara Liskov,The first woman in the United States to be awarded a Ph.D. from a computer science department In 1968, Stanford University She received 2008 Turing Award from the ACM for her work in the design of programming languages and software methodology that led t
4、o the development of object-oriented programming ACM: Association for Computing Machinery The Turing Award The highest distinction in Computer Science The Nobel Prize of computing,Definition,Design by contract Behavioral subtyping Let q(x) be a property provable about objects x of type T. Then q(y)
5、should be true for objects y of type S where S is a subtype of T.,Subtype,A subtype is a datatype that is related to another datatype (the supertype) by some notion of substitutability Program constructs written to operate on elements of the supertype can also operate on elements of the subtype Typi
6、cal program construct: subroutines, functions, methods Polymorphism in object-oriented programming language Subtyping relation is a relation on types On specification level More abstractly, on concepts,Subclass,A subclass is a class that inherits some properties from its superclass A subclass is an
7、extension of its superclass A subclass reuses the properties or services of its superclass Subclass relation is a relation on implementation level superclass, base class, or parent class child classes, derived classes, or subclasses,The principles (1),standard requirements on signatures Contravarian
8、ce of method arguments in the subtype Covariance of return types in the subtype No new exceptions should be thrown by methods of the subtype except where those exceptions are themselves subtypes of exceptions thrown by the methods of the supertype The members of derived classes must expect no more t
9、han the corresponding members of the base class; and should promise no less,The principles (2),Behavioral conditions that subtype must meet Preconditions cannot be strengthened in a subtype Postconditions cannot be weakened in a subtype Invariants of the supertype must be preserved in a subtype Hist
10、ory constraint: the history properties of the supertype must be preseved in a subtype History properties are properties true of all sequences of states e.g. the bound of an array does not change,A typical violation,The square-rectangle problem Also circle-ellipse problem /wiki/
11、Circle-ellipse_problem A square is a rectangle ? The square class inherits the rectangle class will lead to many problems!,Benefits and the risk of fallout from the change increases dramatically.,Separation through delegation (1),Separation through delegation (2),Benefits dont talk to strangers. Onl
12、y talk to your immediate friends.,An example (1),An example (2),An example (3),What is this bad?,The Paperboy class now knows that the customer has a wallet, and can manipulate it “the paperboy is being exposed to more information than he needs to be” It is not corresponding to the real-word These t
13、hree classes are now tightly coupled,Improving the original code (1),Improving the original code (2),What is this better?,it better models the real world scenario The paperboy does not have direct access to the wallet the Wallet class can now change, and the paperboy is completely isolated from that
14、 change Code will be more maintainable, because changes will not ripple through a large project we are now free to change the implementation of getPayment(),The Law of Demeter for functions,A method M of an object O may only invoke the methods of the following kinds of objects O itself Ms parameters any objects created/instantiated within M Os direct component objects,When and how to apply the LoD,Chained get Statements value = object.getX().getY().getTheValue(); Lots of temporary objects Importing Many Cl
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- “JUZI汉语”软件在HSK词汇教学中的应用研究
- JS银行ESG管理体系优化研究
- 读后续写教学中高中英语教师的教学信念对其教学行为影响的个案研究
- 玩具设计核心要素与创新实践
- 孩子作业书写培训
- 电信网络安全班会
- 脑动静脉畸形MRI诊断
- 颐和园英文课件
- 三减三健健康知识教育
- 心内科胸闷气促的护理诊断
- 小儿喘息性肺炎的护理
- 新能源产业中液流电池储能电站项目的成功要素解析
- 2877管理学基础1-15套试题答案 国开
- 2025陕西中考语文试题(含答案)
- 物业培训课件大全
- Unit 1 This is me 语法提升 课件 外研版英语八年级上册
- 中国LNG加气站行业发展分析及发展前景与投资研究报告2025-2028版
- 文化礼堂g管理制度
- 顺昌县土地综合整治项目可行性研究报告
- 乐器演奏团行业深度调研及发展项目商业计划书
- 2024年7月辽宁高中学业水平合格考地理试卷真题(含答案)
评论
0/150
提交评论