契约式设计
Design by Contract
2018/1/1
Institute puter Software
Nanjing University
摘要
引言
Eiffel 的 DbC 机制
DbC与继承
如何应用DbC
2018/1/1
Institute puter Software
Nanjing University
2
引言
Design by Contract (DbC) 契约式设计
方法学层面的思想
以尽可能小的代价开发出可靠性出众的软件系统
Eiffel语言的直接支持
Bertrand Meyer:DbC是构建面向对象软件系统方法的核心!
James McKim:“只要你会写程序,你就会写契约”
2018/1/1
Institute puter Software
Nanjing University
3
引言
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.
(把类和它的客户程序之间的关系看做正式的协议,描述双方的权利和义务)
2018/1/1
Institute puter Software
Nanjing University
4
引言
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.
2018/1/1
Institute puter Software
Nanjing University
5
A human contract
2018/1/1
Institute puter Software
Nanjing University
6
Client
Supplier
(Satisfy precondition:)
Bring package before 4 .; pay fee.
(Satisfy postcondition:)
Deliver package by 10 . next day.
OBLIGATIONS(义务)
(From postcondition:)
Get package delivered by 10 . next day.
(From precondition:)
Not required to do anything if package delivered after 4 ., or fee not paid.
BENEFITS(权益/权利)
deliver
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.
2018/1/1
Institute puter Software
Nanjing University
7
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 bene
契约式设计-课件(PPT演示稿) 来自淘豆网m.daumloan.com转载请标明出处.