91.3913Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.

Slides:



Advertisements
Similar presentations
Design by Contract.
Advertisements

Carlos D. Rivera February 28, 2007 Design-by-Contract.
Design by Contract. Design by contract is the process of developing software based on the notion of contracts between objects, which are expressed as.
Object Design Examples with GRASP
1 Design by Contract Building Reliable Software. 2 Software Correctness Correctness is a relative notion  A program is correct with respect to its specification.
Jan 23, Ron McFadyen1 SSD for a samplePOS Use Case Figure 13.1 Input Events invoke a system operation of the same name same idea as in object-oriented.
Object-Oriented Analysis and Design
Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;
1 Specifying Object Interfaces. 2 Major tasks in this stage: --are there any missing attributes or operations? --how can we reduce coupling, make interface.
Software Testing and Quality Assurance
Static and Dynamic Contract Verifiers For Java Hongming Liu.
NJIT Use Case Model Operation Contracts Prepared By: Sumit Sharma.
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.
ACS-3913Fall 2009 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;
September 2002 R McFadyen1 Domain Model Use Case Model text diagram SSD System operation contracts Design Model Figure 13.3.
Eiffel Language and Design by Contract Contract –An agreement between the client and the supplier Characteristics –Expects some benefits and is prepared.
Sept Ron McFadyen1 Extend Relationship.
1 © Wolfgang Pelz Design by Contract Design by Contract™ Based on material drawn from: Bertrand.
Use Case Model Operation Contracts Prepared By: Sumit Sharma and Sravanthi Gillala.
חוזים – Contracts 1. Larman – Chapter 10 – SSDs 10.2 What are System Sequence Diagrams? (introduction) Use cases describe how external actors interact.
Object-Oriented Analysis and Design
Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative Development Part III Elaboration Iteration I – Basic1.
Computer Science 340 Software Design & Testing Design By Contract.
Ranga Rodrigo. Class is central to object oriented programming.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 9, Object Design: Specifying Interfaces.
Object Oriented Analysis and Design System Events & Contracts.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Use Case Model Operation Contracts Chapter 11 Applying UML and Patterns Craig Larman.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Review ♦ System sequence diagram ♦ Domain model
1 Lecture 6: Operation Contracts. 2 Overview  What is contract ?  The guidelines for writing contracts for the system operations.  Use Case realizations.
Operation Contracts: Getting ready to open the “System” black box All material from Applying UML and Patterns, 3 rd Edition, Craig Larman, chapter 11.
1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות.
Larman ch. 131 Use-Case Model : Adding Detail with operation contracts Larman ch. 13.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
COMP-350 Object-Oriented Analysis and Design Drawing System Sequence Diagrams Reference: Larman, Chapter 9.
Chapter 11 Operation Contracts. What They Are An operation is a specification of a transformation or query that an object may be called on to execute.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Operation Contracts. Primary way to describe system behavior is with use cases Operation contracts provide more details in terms of state changes to objects.
Week 4 Operational Contracts Requirements to Design Logical Architecture.
1 Devon M. Simmonds, Computer Science Department Design by Contract Devon M. Simmonds Computer Science Department University of North Carolina, Wilmington.
Class Design I Class Contracts Readings: 2 nd Ed: Section 9.5, Advanced Topic nd Ed: Section 8.5, Advanced Topic 8.2 Some ideas come from: “Practical.
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.
Domain Model A representation of real-world conceptual classes in a problem domain. The core of object-oriented analysis They are NOT software objects.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
OO Methodology Elaboration Phase Iteration 1- Part 3.
1 Chapter 9: Operation Contracts Chapter 13 in Applying UML and Patterns Book.
CEN th Lecture Advance Software Engineering (CEN-5011) Instructor: Masoud Sadjadi Object Design: Specifying.
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.
Use-Case Model: Adding Detail with Operation Contracts.
1 Design Model Use-Case realizations with GRASP Larman chapter 17.
Design by Contract. The Goal Ensure the correctness of our software (correctness) Recover when it is not correct anyway (robustness) Correctness: Assertions.
1 Object Oriented Analysis and Design System Events & Contracts.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
System Sequence Diagrams and Operation Contracts
Used to help understand requirements more completely
Specifying Object Interfaces
Analysis models and design models
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Computer Science 340 Software Design & Testing
Object Constraint Language (OCL)
Operation Contracts Ch. 11.
Formal Methods Lecture 16 March 22, 2011 CS 315 Spring 2011
Presentation transcript:

Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any element of the UML text discusses contracts for system operations; contracts are applicable to execution of any software component

Feb 2003 R McFadyen2 Domain Model Use Case Model text diagram SSD System operation contracts Design Model Figure 13.3 Relationship between Contracts and other artifacts

Feb 2003 R McFadyen3 Contracts A contract is a technique for describing system operations in terms of state changes to objects in a Domain Model Major proponent - Bertrand Meyer Based on concept of assertion a statement, a constraint or declaration, that must be true a false value indicates a bug may be expressed informally, or in the UML we can (optionally) use the Object Constraint Language (OCL; 1999) to specify constraints rigorously

Feb 2003 R McFadyen4 Constraints Three types pre-condition: must be true before a part of the system executes post-condition: must be true after a part of the system executes invariant: must be true before and after any part of the system is executed. Constraints can be enclosed in braces and placed in a note on a diagram appear as guards on a diagram kept in a separate file managed by a CASE tool

Feb 2003 R McFadyen5 Constraints e.g. Suppose each instance of a Student class has an ageFirstEntry attribute and the age must always be 16 or more. –OCL context Student inv: ageFirstEntry >=16 informal precise Student ageFirstEntry {ageFirstEntry >=16}

Feb 2003 R McFadyen6 Consider the execution of a routine: The called routine provides a service - it is the supplier The caller is the client requesting the service. A contract will spells out precisely the obligations of the caller (client) and the callee (supplier). The contract serves as an interface specification for the routine. Example: consider a routine that merges two sorted sequences. The merge routine is the supplier of the service; the calling routine is the caller. A contract will spell out the responsibilities of each party. Contracts

Feb 2003 R McFadyen7 Responsibilities: Client: Ensure that the both sequences to be merged are each already sorted Supplier: Efficiently merge the two sorted sequences into one sorted sequence Contracts

Feb 2003 R McFadyen8 Software contract: The responsibilities of the client will be called pre- conditions The responsibilities of the supplier will be called post- conditions Pre-condition: both sequences to be merged are each already sorted Post-condition: the two sorted sequences are merged into one sorted sequence Contracts

Feb 2003 R McFadyen9 During analysis developers must first understand the problem domain and identify domain objects, their relationships with other domain objects, and their constraints. If a contract is defined in terms of domain objects the constraints can be clear and explicit, easily understood Everyone understands the business contracting metaphor. Business rules (constraints) can become an integral part of the software from the very beginning. Example: consider a withdraw method for an ACCOUNT class:withdraw (amount_to_withdraw: MONEY) Contracts

Feb 2003 R McFadyen10 Example: consider a withdraw method for an ACCOUNT class: withdraw (amount_to_withdraw: MONEY) Pre-conditions: positive_amount: amount_to_withdraw > 0 sufficient_balance: balance >= amount_to_withdraw Post-conditions: correct_balance: balance = initial balance - amount_to_withdraw Contracts

Feb 2003 R McFadyen11 Contracts Contract Components (Larman) Operation - name and parameters Cross References - where operation used Preconditions - assumptions about the state of the system or Domain Model objects Postconditions - state of objects after the operation completes objects:any new ones? any attributes modified? associations: any new or modified associations? Larman’s version is very informal

Feb 2003 R McFadyen12 SSD for a samplePOS Use Case Figure 13.1 Input Events invoke a system operation of the same name same idea as in object-oriented programming when we say a message foo invokes the method foo Referred to as the enterItem system operation

Feb 2003 R McFadyen13 SalesLineItem quantity Product Specification itemID Sale 1 1..* * 1Described by Contained in The part of the Domain Model relevant to enterItem( )

Feb 2003 R McFadyen14 Contracts Example Operation:enterItem (itemID : ItemID, quantity : integer) Preconditions there is a Sale underway Postconditions a SalesLineItem instance was created an association between the sale and the sales line item was created an attribute, quantity, was modified an association between the product specification and the sales line item was created

Feb 2003 R McFadyen15 Design By Contract (DBC) provides the basis for documenting software interfaces Reusers of a software component need to understand what the software provides them and what they must do to obtain these benefits. This is the contract. DBC is perhaps a best non-practice. Example of a new DBC tool: iContract: Design by Contract in Java allows one to include runtime assertions for development purposes and suppress them for production cooltools.html