Design by Contract Jim Fawcett CSE784 – Software Studio

Slides:



Advertisements
Similar presentations
Design by Contract.
Advertisements

Ceg860(Prasad)L10DC1 Design by Contract Invariants Pre-post conditions : Rights and Obligations Exceptions : Contract Violations.
Building Bug-Free O-O Software: An Introduction to Design By Contract A presentation about Design By Contract and the Eiffel software development tool.
Building bug-free O-O software: An introduction to Design by Contract Eiffel Software Presented by Bert Bruce.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Design by Contract ™. 2 Design by Contract A discipline of analysis, design, implementation, management.
Object Oriented Design An object combines data and operations on that data (object is an instance of class) data: class variables operations: methods Three.
Chair of Software Engineering ATOT - Lecture 10, 5 May Advanced Topics in Object Technology Bertrand Meyer.
Design by Contract. Specifications Correctness formula (Hoare triple) {P} A {Q} – A is some operation (for example, a routine body) – P and Q are predicates.
Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;
Component-Based Software Engineering Components and Interfaces Paul Krause.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Software Testing and Quality Assurance
Chair of Software Engineering ATOT - Lecture 12, 12 May Advanced Topics in Object Technology Bertrand Meyer.
Static and Dynamic Contract Verifiers For Java Hongming Liu.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chair of Software Engineering 1 Introduction to Programming Bertrand Meyer Exercise Session 6 7 October 2008.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chair of Software Engineering Concurrent Object-Oriented Programming Prof. Dr. Bertrand Meyer Lecture 9: Contracts and Inheritance (based on work with.
Chair of Software Engineering 1 Introduction to Programming Exercise Session Week 9 M. Piccioni 17/18 November 2008.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 6: Object Creation.
1 Introduction to: Design by Contract Fall 2005 OOPD John Anthony.
Describing Syntax and Semantics
Eiffel Language and Design by Contract Contract –An agreement between the client and the supplier Characteristics –Expects some benefits and is prepared.
1 © Wolfgang Pelz Design by Contract Design by Contract™ Based on material drawn from: Bertrand.
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
Component-Based Software Engineering Components and Interfaces Paul Krause.
Ranga Rodrigo. Class is central to object oriented programming.
Design by contract. A software system is viewed as a set of communicating components whose interaction is based on precisely defined specifications of.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Tammy Dahlgren with Tom Epperly, Scott Kohn, and Gary Kumfert Center for Applied Scientific Computing Common Component Architecture Working Group October.
Design by Contract in Java Concept and Comparison.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
More About Classes Ranga Rodrigo. Information hiding. Copying objects.
OOSCCh11r1:DbC RJL Slide #1 OOSC: Ch11 vs. Predecessors [Meyer:] Equipped with the basic concepts of class, object and genericity, you can by now.
Contracts for Concurrency - Contracts & Inheritance Aryabrata Basu University of Georgia.
CSC 480 Software Engineering Design by Contract. Detail Design Road Map Begin with architectural models  Class model: domain classes  Overall state.
1 Devon M. Simmonds, Computer Science Department Design by Contract Devon M. Simmonds Computer Science Department University of North Carolina, Wilmington.
L13: Design by Contract Definition Reliability Correctness Pre- and post-condition Asserts and Exceptions Weak & Strong Conditions Class invariants Conditions.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
Object-Oriented Design Concepts University of Sunderland.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Component-Based Software Engineering Components and Interfaces Paul Krause and Sotiris Moschoyiannis.
Page 1, CBSE – graduate course Specification of Software Components Frank Lüders Mälardalen University, Dept. of Computer Engineering
Chapter 3 of Programming Languages by Ravi Sethi
Design by Contract Jim Fawcett CSE784 – Software Studio
Used to help understand requirements more completely
Arab Open University 2nd Semester, M301 Unit 5
Topics: jGRASP editor ideosyncrasies assert debugger.
TIM 58 Chapter 8: Class and Method Design
Design by Contract Fall 2016 Version.
Programming Languages 2nd edition Tucker and Noonan
Design by contract Object-Oriented Software Construction by Bertrand Meyer, Prentice Hall The presence of a precondition or postcondition in a routine.
An Introduction to Software Architecture
Design by contract Object-Oriented Software Construction by Bertrand Meyer, Prentice Hall The presence of a precondition or postcondition in a routine.
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Object Constraint Language (OCL)
Contract-Based Programming with/without Ada 2012
Programming Languages 2nd edition Tucker and Noonan
Design Contracts and Errors A Software Development Strategy
Presentation transcript:

Design by Contract Jim Fawcett CSE784 – Software Studio Paraphrased from works of Bertrand Meyer Interactive Software Engineering, www.eiffel.com

Motivation “Reliability … is particularly important in the object-oriented method because of the special role given by the method to reusability:” “Unless we can obtain reusable software components whose correctness we can trust … reusability is a losing proposition.” “To be sure that our object-oriented software will perform properly, we need a systematic approach to specifying and implementing … software elements and their relations …” “Under the Design by Contract theory, a software system is viewed as a set of communicating components whose interaction is based on precisely defined specifications of the mutual obligations – contracts.” All quotes here and in the following pages from Bertrand Meyer: www.eiffel.com/doc/manuals/technology/contract

Preconditions and Postconditions An Eiffel Example from ISE: In Eiffel syntax, a routine put, that is part of a generic class DICTIONARY [ELEMENT], might be defined by: put (x: ELEMENT; key: STRING) is -- Insert x so that it will be retrievable through key. require count <= capacity not key.empty do ... Some insertion algorithm ... ensure has (x) item (key) = x count = old count + 1 end

Comments on the Eiffel Example “The require clause introduces an input condition, or precondition.” “The ensure clause introduces an output condition, or postcondition.” “Both of these conditions are examples of assertions, or logical conditions (contract clauses) associated with software elements.” “In the precondition, count is the current number of elements and capacity is the maximum number.” “In the postcondition, has is the boolean query which tells whether a certain element is present, and item returns the element associated with a certain key. The notation old count refers to the value of count on entry to the routine.” If either of these assertions is violated, an exception is thrown.

Invariants “Preconditions and postconditions apply to individual routines. Other kinds of assertions will characterize a class as a whole, rather than its individual routines. An assertion describing a property which holds of all instances of a class is called a class invariant.” “The invariant of DICTIONARY could state invariant 0 <= count count <= capacity” “Class invariants are consistency constraints characterizing the semantics of a class. This notion is important for configuration management and regression testing, since it describes the deeper properties of a class: not just the characteristics it has at at a certain moment of its evolution, but the constraints which must also apply to subsequent changes.” “Viewed from the contract theory, an invariant is a general clause which applies to the entire set of contracts defining a class.”

Contract Documentation “A short form, which is stripped of all implementation information but retains the essential usage information: the contract … .” class interface DICTIONARY [ELEMENT] feature put (x: ELEMENT; key: STRING) is -- Insert x so that it will be retrievable -- through key. require count <= capacity not key.empty ensure has (x) item (key) = x count = old count + 1 ... Interface specifications of other features Invariant 0 <= count count <= capacity end -- class interface DICTIONARY

Contracts and Inheritance A derived class is a subcontractor. “A class B which inherits from a class A may provide a new declaration for a certain inherited feature r of A. In the call a.r the target a of the call, although declared statically of type A, could in fact be attached at run time to an object of type B.” [Operates like a C++ reference] “Then dynamic binding implies that the B version of r will be called …”.

Contracts and Inheritance “This is a form of subcontracting: A subcontracts r to B for targets of the corresponding type. But a subcontractor must be bound by the original contract. A client which executes a call under the form if a.pre then a.r end must be guaranteed the contractually promised result: the call will be correctly executed since the precondition is satisfied (assuming that pre implies the precondition of r); and on exit a.post will be true, where post is the postcondition of r.” [I have applied some formatting to the original quote – J.F.]

Principle of Subcontracting “The principle of subcontracting follows from these observations: a redefined version of r may keep or weaken the precondition [by removing conditions in require clause, e.g., on callers]; it may keep or strengthen the postcondition [by adding conditions in ensure clause, e.g., on implementation]. Strengthening the precondition, or weakening the postcondition, would be a case of "dishonest subcontracting" and could lead to disaster. The Eiffel language rules for assertion redefinition … support the principle of subcontracting.” “These observations shed light on the true significance of inheritance: not just a reuse, subtyping and classification mechanism, but a way to ensure compatible semantics by other means. They also provide useful guidance as to how to use inheritance properly.”