Operation Contracts Operation Contracts Primary way to describe

Operation Contracts

Operation Contracts • Primary way to describe system behavior is with use cases • Operation contracts provide more details in terms of state changes to objects in domain model after system operation has executed postconditions

Contract CO 2: enter. Item Operation: Cross references: Preconditions: Postconditions: enter. Item(item. ID : Item. ID, quantity : integer) Process Sale use case There is a sale underway - A Sales. Line. Item instance sli was created (instance creation) - sli was associated with the current Sale (association formed) - sli. quantity became quantity (attribute modification) - sli was associated with a Product. Description, based on item. ID match (association formed)

Fig. 11. 1

Format of Operation Contract sections: – Operation – name and parameters – Cross References – use cases that apply – Preconditions – Postconditions

Operation Contracts Postconditions – describe changes in state of objects in the domain model including: • Instances created and deleted • Associations formed or broken • Attributes changed

Operation Contracts • Similar to use case but provides more detail • Expressed in a declarative form not as an action • Provide more detail on postconditions • Postconditions expressed in past tense

Operation Contracts Guideline: How to create and write contracts: – Identify system operations from SSDs – Construct a contract for those system operations that are complex or subtle in their results – Describe postconditions using terms: • Instance creation/deletion • Attribute modification • Associations formed/broken

Contract CO 1: make. New. Sale Operation: Cross references: Preconditions: Postconditions: make. New. Sale() Process Sale use case None - A Sale instance s was created (instance creation) - s was associated with a Register (association formed) - Attributes of s were initialized

Fig. 9. 27

Contract CO 3: end. Sale Operation: Cross references: Preconditions: Postconditions: end. Sale() Process Sale use case There is a sale underway - Sale. is. Complete became true (attribute modification)

Contract CO 4: make. Payment Operation: Cross references: Preconditions: make. Payment(amount : Money) Process Sale use case There is a sale underway Postconditions: - A Payment instance p was created (instance creation) - p. amount. Tendered became amount (attribute modification) - p was associated with the current Sale (association formed) - The current Sale was associated with the Store (association formed)
- Slides: 12