Presentation is loading. Please wait.

Presentation is loading. Please wait.

92.3913Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;

Similar presentations


Presentation on theme: "92.3913Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;"— Presentation transcript:

1 92.3913Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) 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

2 92.3913Jan 2005 Ron McFadyen2 Domain Model Use Case Model text diagram SSD System operation contracts Design Model

3 92.3913Jan 2005 Ron McFadyen3 Contracts A contract is a technique for describing system operations in terms of state changes to objects in a Domain Model Contracts are based on work by Bertrand Meyer … Eiffel programming language and the concept of assertion a statement, a constraint or declaration, that must be true a false value indicates a bug

4 92.3913Jan 2005 Ron 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.

5 92.3913Jan 2005 Ron McFadyen5 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

6 92.3913Jan 2005 Ron McFadyen6 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 Software contract: The responsibilities of the client will be called pre- conditions The responsibilities of the supplier will be called post- conditions

7 92.3913Jan 2005 Ron McFadyen7 Pre-condition: both sequences to be merged are each already sorted Post-condition: the two sorted sequences are merged into one sorted sequence Contracts

8 92.3913Jan 2005 Ron McFadyen8 Contracts Contract Components (Larman) Operation - name and parameters Cross References – where (use cases) operation used Preconditions – noteworthy 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

9 92.3913Jan 2005 Ron McFadyen9 SSD for a samplePOS Use Case 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 (correctly) as the enterItem system operation in 3 rd edition

10 92.3913Jan 2005 Ron McFadyen10 SalesLineItem quantity Product Specification itemID Sale 1 1..* * 1Described by Contained in The part of the Domain Model relevant to enterItem( ) – discussed in a later chapter

11 92.3913Jan 2005 Ron McFadyen11 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

12 92.3913Jan 2005 Ron McFadyen12 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 http://www.javaworld.com/javaworld/jw-02-2001/jw- 0216-cooltools.html Aside


Download ppt "92.3913Jan 2005 Ron McFadyen1 Contracts Used to help understand requirements more completely (and so may not always be necessary) based on assertions;"

Similar presentations


Ads by Google