140 likes | 251 Views
COMP 6471 Software Design Methodologies. Winter 2006 Dr Greg Butler http://www.cs.concordia.ca/~gregb/home/comp647-w2006.html. Ch 11: Operation Contracts. Aim: Define system operations via contracts Operation Method Invariant Precondition Postcondition. Context within artefacts.
E N D
COMP 6471Software Design Methodologies Winter 2006 Dr Greg Butler http://www.cs.concordia.ca/~gregb/home/comp647-w2006.html
Ch 11: Operation Contracts Aim: Define system operations via contracts Operation Method Invariant Precondition Postcondition
UML Definitions Event A significant or noteworthy occurrence. Operation An operation is a specification of a transformation or query that an object may be called to execute. [RJB1999] Signature of an operation specifies the name, parameters, and return type (and exceptions thrown). Pre-conditions and post-conditions are UML constraints specified using OCL (Object Constraint Language). Method [A method is] the implementation of an operation. It specifies the algorithm or procedure associated with an operation [OMG 2003]
Definitions Contract A contract specifies detailed changes, as a result of a system operation, to objects in the domain model using pre-conditions and post-conditions. Contract Format • Operation: name and parameters of operation. • Cross References: use cases that involve the operation. • Preconditions: noteworthy assumptions about the state of the system or object in the domain model before execution of the operation. • Postconditions: The state of objects in the domain model after completion of the operation. State A state is the condition of an object (or system) at a moment in time.
Describing the State of a System Describe the objects in the system Describe the links (relationships) between the objects Describe the properties of each object (ie the state of the object) = the (abstract) values of the object attributes [as in a state machine]
Example: State of CUWME Objects • users is the set of all User objects • roles is the set of all Role objects • projects is the set of all Project objects • Plus files, documents, … Links • u works_on p for User and Project objects • p owns d for Project and Document objects • d is_stored_as f for Document and File objects • … Object States • Document d has state “reviewed” • p.activity[3].status = “completed” • …
Invariant of a System or Object Invariant Is a condition which is always true about the state of the system (or object) Note: the state is only defined in between execution of operations Hence, invariant only has to be true before and after each operation, not during an operation
Example Invariants of CUWME(These depend on your abstractions/assumptions.) Each document is owned by exactly one project. Each project owns exactly one document. Each user has precisely one role in a given project. A user may only access documents owned by the projects that a user is working on. A document may be stored in more than one file. A file has only a single location. …
Postcondition Definition The postconditions describe changes in the state of objects in the domain model. Domain model state changes include instances created, associations formed or broken, and attributes changed. Note: postconditions are not actions to be performed during the operation They are the effect, ie observations about state of domain objects when the operation is finished. Ie, “what” not “how”
Writing Postconditions Document • Instance creation and deletion “A SalesLineItem sli was created” • Attribute change of value “sli.quantity became quantity” Note: quantity is an operation parameter • Association links formed and broken “sli was linked to the current Sale” “sli was linked with a productDescription based on itemID match” Use past tense.
Guidelines • Identify system operations from the SSDs. • For system operations that are complex and perhaps subtle in their results, or which are not clear in the use case, construct a contract. • To describe the postconditions, document • Instance creation and deletion • Attribute modification • Links formed and broken Use past tense for postconditions. Remember to document the forming of links!