南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)04 契约式设计 Design by Contract

Design by Contract 契约式设计 Institute of Computer Software 2022-2-27 Nanjing University
契约式设计 Design by Contract 2022-2-27 Institute of Computer Software Nanjing University

&雪扇 摘要 UNIVE 2 口引言 o Eiffel的DbC机制 口DbC与继承 口如何应用DbC Institute of Computer Software 2022-2-27 Nanjing University
摘要 引言 Eiffel 的 DbC 机制 DbC与继承 如何应用DbC 2022-2-27 Institute of Computer Software Nanjing University 2

引言 1902 3 口Design by Contract(DbC)契约式设计 口方法学层面的思想 ■以尽可能小的代价开发出可靠性出众的软件系统 Eiffel语言的直接支持 Bertrand Meyer:DbC是构建面向对象软件系统方法 O 的核心! 口James McKim:“只要你会写程序,你就会写契约” Institute of Computer Software 2022-2-27 Nanjing University
引言 Design by Contract (DbC) 契约式设计 方法学层面的思想 以尽可能小的代价开发出可靠性出众的软件系统 Eiffel语言的直接支持 Bertrand Meyer:DbC是构建面向对象软件系统方法 的核心! James McKim: “只要你会写程序,你就会写契约” 2022-2-27 Institute of Computer Software Nanjing University 3

引言 1902 4 A discipline of analysis,design,implementation, management (可以贯穿于软件创建的全过程,从分析到设计,从文 档到调试,甚至可以渗透到项目管理中) Viewing the relationship between a class and its clients as a formal agreement,expressing each party's rights and obligations. (把类和它的客户程序之间的关系看做正式的协议,描 述双方的权利和义务) Institute of Computer Software 2022-2-27 Nanjing University
引言 A discipline of analysis, design, implementation, management (可以贯穿于软件创建的全过程,从分析到设计,从文 档到调试,甚至可以渗透到项目管理中) Viewing the relationship between a class and its clients as a formal agreement, expressing each party ’ s rights and obligations. (把类和它的客户程序之间的关系看做正式的协议,描 述双方的权利和义务) 2022-2-27 Institute of Computer Software Nanjing University 4

&扇 NAN 引言 1902 5 o Every software element is intended to satisfy a certain goal,for the benefit of other software elements(and ultimately of human users). This goal is the element's contract. The contract of any software element should be ▣Explicit.. Part of the software element itself. Institute of Computer Software 2022-2-27 Nanjing University
引言 Every software element is intended to satisfy a certain goal, for the benefit of other software elements (and ultimately of human users). This goal is the element’ s contract. The contract of any software element should be Explicit. Part of the software element itself. 2022-2-27 Institute of Computer Software Nanjing University 5

&雪扇 A human contract 102 UNIVE 6 deliver OBLIGATIONS(义务) BENEFITS(权益/权利) Client (Satisfy precondition: (From postcondition: Bring package before Get package delivered 4 p.m.;pay fee. by 10 a.m.next day. (Satisfy postcondition: (From precondition: Supplier Deliver package by Not required to do 10 a.m.next day. anything if package delivered after 4 p.m., or fee not paid. Institute of Computer Software 2022-2-27 Nanjing University
A human contract 2022-2-27 Institute of Computer Software Nanjing University 6 Client Supplier (Satisfy precondition:) Bring package before 4 p.m.; pay fee. (Satisfy postcondition:) Deliver package by 10 a.m. next day. OBLIGATIONS(义务) (From postcondition:) Get package delivered by 10 a.m. next day. (From precondition:) Not required to do anything if package delivered after 4 p.m., or fee not paid. BENEFITS(权益/权利) deliver

&扇 NAN A view of software construction UNIVE ▣ Constructing systems as structured collections of cooperating software elements -suppliers and clients -cooperating on the basis of clear definitions of obligations and benefits. These definitions are the contracts. Institute of Computer Software 2022-2-27 Nanjing University
A view of software construction Constructing systems as structured collections of cooperating software elements — suppliers and clients — cooperating on the basis of clear definitions of obligations and benefits. These definitions are the contracts. 2022-2-27 Institute of Computer Software Nanjing University 7

Properties of contracts 102 8 ▣A contract: Binds two parties(or more):supplier,client. Is explicit (written). Specifies mutual obligations and benefits. Usually maps obligation for one of the parties into benefit for the other,and conversely. Has no hidden clauses:obligations are those specified. Often relies,implicitly or explicitly,on general rules applicable to all contracts(laws,regulations,standard practices). Institute of Computer Software 2022-2-27 Nanjing University
Properties of contracts A contract: Binds two parties (or more): supplier, client. Is explicit (written). Specifies mutual obligations and benefits. Usually maps obligation for one of the parties into benefit for the other, and conversely. Has no hidden clauses: obligations are those specified. Often relies, implicitly or explicitly, on general rules applicable to all contracts (laws, regulations, standard practices). 2022-2-27 Institute of Computer Software Nanjing University 8

Contracts for analysis deferred class PLANE inherit AIRCRAFT feature start_take_off is Precondition --Initiate take-off procedures. require controls.passed --i.e.specified only. assigned_runway.clear deferred --not implemented. ensure assigned_runway.owner Current moving Postcondition end start_landing,increase_altitude,decrease_altitude,moving, altitude,speed,time_since_take_off .[Other features]… Class invariant invariant (time_since_take_off <=20)implies (assigned_runway.owner Current) moving =(speed 10) 9 end Institute of Computer Software 2022-2-27 Nanjing University
2022-2-27 Institute of Computer Software Nanjing University 9 deferred class PLANE inherit AIRCRAFT feature start_take_off is -- Initiate take-off procedures. require controls.passed assigned_runway.clear deferred ensure assigned_runway.owner = Current moving end start_landing, increase_altitude, decrease_altitude, moving, altitude, speed, time_since_take_off ... [Other features] ... invariant (time_since_take_off 10) end Contracts for analysis Precondition Class invariant -- i.e. specified only. -- not implemented. Postcondition

Contracts for analysis(cont'd) deferred class VAT inherit TANK feature in_valve,out_valve:VALVE fill is -Fill the vat. Precondition require in_valve.open out_valve.closed --i.e.specified only. deferred ensure --not implemented. in_valve.closed out_valve.closed is full Postcondition end empty,is_full,is_empty,gauge,maximum,...[Other features]... Class invariant invariant is_full =(gauge >=0.97 maximum)and (gauge <=1.03 maximum) end 10 Institute of Computer Software 2022-2-27 Nanjing University
2022-2-27 Institute of Computer Software Nanjing University 10 deferred class VAT inherit TANK feature in_valve, out_valve: VALVE fill is -- Fill the vat. require in_valve.open out_valve.closed deferred ensure in_valve.closed out_valve.closed is_full end empty, is_full, is_empty, gauge, maximum, ... [Other features] ... invariant is_full = (gauge >= 0.97 * maximum) and (gauge <= 1.03 * maximum) end Contracts for analysis (cont’d) Precondition Class invariant -- i.e. specified only. -- not implemented. Postcondition
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)03 类和对象 Class and Object.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)02 抽象数据类型 Abstract Data Types.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)01 Introduction(主讲:余萍).ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第16讲 信息系统应用.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第15讲 信息系统管理.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第14讲 实现与测试.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第13讲 系统设计实践(小区物业管理系统).ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第12讲 详细设计(下)界面设计.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第11讲 详细设计(中)数据库设计.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第10讲 详细设计(上).ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第09讲 体系结构设计.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第08讲 需求建模与总结.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第07讲 需求分析实践.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第06讲 需求分析.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第05讲 领域分析.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第04讲 信息系统规划.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第03讲 信息系统建设.ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第02讲 信息系统导论(下).ppt
- 西安石油大学计算机学院:《信息系统分析与设计 Information System Analysis and Design》课程教学资源(PPT课件)第01讲 信息系统导论(上).ppt
- 西安石油大学计算机学院:《软件建模技术——软件建模与UML》课程教学资源《软件建模技术》试题2011年上A.doc
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)05 异常处理 Exception Handling.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)06 并发对象 Concurrent Objects.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)07 Java并发编程 Concurrent Programming in Java.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)08 对象序列化和持久化 Serialization and Persistence.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)09 面向对象的分析与设计简介 OOA & OOD:An introduction.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)10 敏捷软件开发 Agile Software Development.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)11 设计模式 Design Patterns(1).ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)12 设计模式 Design Patterns(2).ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)13 设计模式 Design Patterns(3).ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)14 模式和框架 Pattern and Framework.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)15 面向方面的编程 Aspect Oriented Programming(AOP).ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)16 构件化软件 Component Software.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)17 分布对象 Distributed Objects(1).ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)18 分布对象 Distributed Objects(2).ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)19 复习和总结 Object-Oriented Technology:Review and Conclusion Remarks.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)实习项目概述.ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(实习指南)医院预约挂号系统.docx
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)OOT实习指南.pptx
- 南京大学:《面向对象技术 OOT》课程教学资源(教材电子版)33 O-O programming and Ada.pdf
- 南京大学:《面向对象技术 OOT》课程教学资源(教材电子版)06 Abstract data types.pdf