I. adding detail with operation contracts (Larman Ch. 13) ------------------------------------------ ADDING DETAIL WITH OPERATION CONTRACTS (Larman, Ch 13) A contract: precondition: - says when calls are legal - describes domain (pre-state) postcondition - describes effects of a call - instance creation - attribute modification - associations forms and broken - relates pre-state to post-state Contract C01: makeNewSale Operation: makeNewSale(reg: Register) Cross Reference: Use Cases: Process Sale Preconditions: - none Postconditions: - A new sale instance s is associated with reg - attributes of s are initialized ------------------------------------------ A. analogy 1. contracting ------------------------------------------ BENEFITS AND OBLIGATIONS Client/ Server/ Caller Implementor ========================================== Precond. | obligation assumes | (cost) (benefit) | Postcond.| assumes obligation | (benefit) (cost) ------------------------------------------ Is the precondition tested by an operation's implementation? 2. stage and curtain (p. 181) ------------------------------------------ THE STAGE AND THE CURTAIN (p. 181) 0. Director compares stage setup to pile of scripts 1. Take picture of stage 2. Close the curtains (action takes place) 3. Open curtains, compare pre-act picture to current stage ------------------------------------------ B. examples ------------------------------------------ Contract C02: addLineItem Operation: addLineItem(s: Sale, itemID: itemID, quantity: integer) Cross Reference: Use Cases: Process Sale Preconditions: - none Postconditions: - ------------------------------------------ C. level ------------------------------------------ LEVEL FOR WRITING CONTRACTS Write contracts at domain model level: - objects - associations - attributes ------------------------------------------ D. writing contracts leads to domain model updates (13.6) E. advice (13.7-13.8) ------------------------------------------ ADVICE ABOUT CONTACTS (13.7-13.8) To make contracts: 1. Identify system operations from SSDs 2. For those that are complex or subtle, or whch are not clear, make contracts. 3. Postconditions should describe: - instances created or deleted - attributes modified - associations formed and broken Describe what, now how. Remember associations needed establish a memory of information.her ------------------------------------------ F. relation to test plan ------------------------------------------ RELATION TO TESTING Can use contracts to tell what to test Precondition: describes test inputs Postcondition: describes when tests pass ------------------------------------------ G. practice Can you write some contracts for some of your system operations?