1 © Wolfgang Pelz 2000-04Design by Contract Design by Contract™ Based on material drawn from: www.eiffel.com/doc/manuals/technology/contract/ Bertrand.

Slides:



Advertisements
Similar presentations
Where Agile Meets Formal Methods
Advertisements

Design by Contract.
Building Bug-Free O-O Software: An Introduction to Design By Contract A presentation about Design By Contract and the Eiffel software development tool.
Carlos D. Rivera February 28, 2007 Design-by-Contract.
272: Software Engineering Fall 2012
Design by Contract. Design by contract is the process of developing software based on the notion of contracts between objects, which are expressed as.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.
Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 15: Exception handling.
Component-Based Software Engineering Components and Interfaces Paul Krause.
-5- Exception handling What is an exception? “An abnormal event” Not a very precise definition Informally: something that you don’t want to happen.
Software Testing and Quality Assurance
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 10: Project Presentation Ilinca.
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 4: The Interface of a Class.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Planning and Estimating
Karlstad University Computer Science Design Contracts and Error Management Design Contracts and Errors A Software Development Strategy (anpassad för PUMA)
September 2002 R McFadyen1 Domain Model Use Case Model text diagram SSD System operation contracts Design Model Figure 13.3.
Chapter 1 Principles of Programming and Software Engineering.
1 Introduction to: Design by Contract Fall 2005 OOPD John Anthony.
Eiffel Language and Design by Contract Contract –An agreement between the client and the supplier Characteristics –Expects some benefits and is prepared.
Adding Contracts to Ada Ehud Lamm Adding Design By Contract to Ada.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Sept Ron McFadyen1 Extend Relationship.
Computer Science 340 Software Design & Testing Design By Contract.
Ranga Rodrigo. Class is central to object oriented programming.
PRAGMATIC PARANOIA Steven Hadfield & Anthony Rice.
Lecture 16 March 22, 2011 Formal Methods CS 315 Spring Adapted from slides provided by Jason Hallstrom and Murali Sitaraman (Clemson)
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Design by Contract in Java Concept and Comparison.
SWE 619 © Paul Ammann Procedural Abstraction and Design by Contract Paul Ammann Information & Software Engineering SWE 619 Software Construction cs.gmu.edu/~pammann/
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Design by Contract Ranga Rodrigo based on Mark Priestley's Lectures.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
1 Devon M. Simmonds, Computer Science Department Design by Contract Devon M. Simmonds Computer Science Department University of North Carolina, Wilmington.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
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.
Karlstad University Computer Science Design Contracts and Error Management External and internal errors and their contracts.
Defensive Programming CNS 3370 Copyright 2003, Fresh Sources, Inc.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Object-Oriented Design Concepts University of Sunderland.
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.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 10: Programming Exceptionally.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
Design by Contract. The Goal Ensure the correctness of our software (correctness) Recover when it is not correct anyway (robustness) Correctness: Assertions.
© 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.
Principles of Programming & Software Engineering
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
Types for Programs and Proofs
Used to help understand requirements more completely
Principles of Programming and Software Engineering
Design by Contract in Python: Present and Future Aaron Bingham
Introduction to Systems Analysis and Design
Design by contract Object-Oriented Software Construction by Bertrand Meyer, Prentice Hall The presence of a precondition or postcondition in a routine.
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.
Computer Science 340 Software Design & Testing
Formal Methods Lecture 16 March 22, 2011 CS 315 Spring 2011
Design by Contract – Exceptions
Design Contracts and Errors A Software Development Strategy
Presentation transcript:

1 © Wolfgang Pelz Design by Contract Design by Contract™ Based on material drawn from: Bertrand Meyer, Applying “Design by Contract,” IEEE Computer, 1992, pp

2 © Wolfgang Pelz Design by Contract Basic Premise To improve software reliability, the first and perhaps most difficult problem is to define as precisely as possible, for each software element, what it is supposed to do.

3 © Wolfgang Pelz Design by Contract Design by Contract ™ associate a specification with every software element these specifications (or contracts) govern the interaction of the element with the rest of the world.

4 © Wolfgang Pelz Design by Contract Benefits A better understanding of the object- oriented method and, more generally, of software construction. A systematic approach to building bug-free object-oriented systems. An effective framework for debugging, testing and, more generally, quality assurance.

5 © Wolfgang Pelz Design by Contract More Benefits A method for documenting software components. Better understanding and control of the inheritance mechanism. A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.

6 © Wolfgang Pelz Design by Contract Tabular Form of Contract Party Obligations Benefits Client Provide letter or package Get package delivered of no more than 5 kgs, each in 4 hours or less dimension < 2 meters. Pay 100 francs. UPS2 Deliver package to recipient No need to deal with in 4 hours or less. deliveries too big, too heavy, or unpaid.

7 © Wolfgang Pelz Design by Contract Rationale a contract document protects both the client, by specifying how much should be done, and the supplier, by stating that the supplier is not liable for failing to carry out tasks outside of the specified scope the obligations of the supplier become the benefits to the client

8 © Wolfgang Pelz Design by Contract Rationale restated a contract protects both sides: protects the client by specifying how much should be done; the client is entitled to receive a certain result protects the contractor by specifying how little is acceptable; the contractor must not be liable for failing to carry out tasks outside of the specified scope

9 © Wolfgang Pelz Design by Contract Assertions preconditions and postconditions routine_name (argument declarations) is require Precondition do Routine body (instructions) ensure Postcondition end

10 © Wolfgang Pelz Design by Contract Violation of an Assertion a precondition violation indicates a bug in the client (caller); the caller did not observe the conditions imposed on correct calls a postcondition violation is a bug in the supplier (called routine); the routine failed to deliver on its promises

11 © Wolfgang Pelz Design by Contract Defensive Programming requires redundant checks in both the client and the supplier not necessary if assertions are used in writing the software to spell out the consistency conditions which could go wrong at runtime

12 © Wolfgang Pelz Design by Contract Effect on Software strong preconditions –heavier burden on the client –lighter burden on the supplier dealing with abnormal values is a pragmatic decision about division of labor in many existing programs, one searches for islands of useful processing midst oceans of error-checking code due to redundancy

13 © Wolfgang Pelz Design by Contract Assertion in VC++ iend.asphttp:// iend.asp assert(condition); // fail if the condition is not true. void CMyClass::MyFunc(char * szStringPtr) { if (szStringPtr[0] == '7') DoSomething(); }

14 © Wolfgang Pelz Design by Contract Assertion in VC++ void CMyClass:: MyFunc(char * szStringPtr) { ASSERT(szStringPtr); if (szStringPtr[0] == '7') DoSomething(); }

15 © Wolfgang Pelz Design by Contract Assertion in VC++ Debug assertion failure When I close my program and call: delete *iter2; I get a "Debug Assertion Failed!" message saying: File: dbgheap.c Line: 1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) What does this mean?

16 © Wolfgang Pelz Design by Contract Documenting a Contract assertions express the purpose of the software elements (e.g., routines) without reference to implementation details still a research subject for the contract to work properly, the client programmers must have a proper description of the interface properties of a class and its routines