Collaboration Diagrams Represent Object roles in a scenario
Collaboration Diagrams • Represent Object roles in a scenario of interactions • Are synonymous to sequence diagrams • Use the same message formats • Used to understand the structure of a scenario • Used to concentrate on what happens to each instance as a whole. • Can be converted to sequence scenarios
Collaboration Diagrams
3 Contracts è Contracts are documents that describe system behavior. è Contracts may be defined for system operations. è è Operations that the system (as a black box) offers in its public interface to handle incoming system events. The entire set of system operations across all use cases, defines the public system interface.
4 SSD for Buy. Item use case
5 System Operations and the System Interface è In the UML the system as a whole can be represented as a class. è Contracts are written for each system operation to describe its behavior.
6 Guidelines for Contracts
7 Use Case Realizations è A use case realization describes how a use case is realized in terms of collaborating objects. è UML interaction diagrams are used to illustrate use case realizations. è Recall Process Sale: from main scenario we identified a number of system events (operations). è Each system event was then described by a contract.
8 Contracts è A contract is a document that describes what an operation commits to achieve. è è Emphasizing what will happen rather than how it will be achieved. Contracts can be expressed by pre- and post- conditions.
9 Conceptual Model and Contracts è A Conceptual Model is a visual representation of conceptual classes or realworld objects in a domain of interest. è Contracts describe detailed system behavior in term of state changes to objects in the Domain Model, after a system operation has executed.
10 Utilize Conceptual Model è To make contracts you have to use the conceptual model. è We added the conceptual model from previous slides to assist the comprehension of post conditions in the contracts.
Domain Model 11
12 Example: Add. Line. Item Contract CO 2: Add. Line. Item Operation: add. Line. Item (item. ID: Item. ID, quantity: integer) Cross References: Use Cases: Process Sale. Pre-conditions: There is a sale underway. Post-conditions: § A Sales. Line. Item instance sli was created. (instance creation) § sli was associated with the current Sale. (association formed) § sli. quantity was set to quantity. (attribute modification) § sli was associated with a Product. Specification, based on item. ID match. (association formed)
13 Pre- & Post- Conditions è Preconditions are assumptions about the state of the system before execution of the operation. è A Postcondition is an assumption that refers to the state of the system after completion of the operation. è The postconditions are not actions to be performed during the operation. è Describe changes in the state of the objects in the Domain Model (instances created, associations are being formed or broken, and attributes are changed).
14 How to Make a Contract 1. Identify system operations from the system sequence diagrams. 2. For each system operation, construct a contract. 3. Write the preconditions section. 4. Write the postconditions section describing the state changes that occur to concepts in the conceptual model. Postconditon categories: è Instance creation and deletion. è Attribute modification. è Associations formed and broken.
15 Add. Line. Item Postconditions Instance Creation and Deletion è After the item. ID and quantity of an item have been entered by the cashier, what new objects should have been created? è A Sale. Line. Item instance sli was created.
16 Add. Line. Item Postconditions Attribute Modification è After the item. ID and quantity of an item have been entered by the cashier, what attributes of new or existing objects should have been modified? è sli. quantity was set to quantity.
17 Add. Line. Item Postconditions Associations Formed and Broken After the item. ID and quantity of an item have been entered by the cashier, what associations of new or existing objects should have been formed or broken? è è sli was associated with the current Sale. è sli was associated with a Product. Specification, based on item. ID match.
18 Make New Sale Enumeration Example è Assume a new sale is started, we will create a new object from the conceptual class Sale, with an ID=5. è If this sale started on the register number 3, then we have to create an association between the sale number 5 with the register number 3 (associations are established by updating foreign keys).
19 Writing Contracts leads to Domain Model Updates è It is also common to discover the need to record new concepts, attributes or associations in the Domain Model. è For example: è If in one of the postconditions, you wanted to create an instance to store some values in it, and it was not presented by any Concept in the domain model. è Then you should go back and correct your domain model by adding this concept.
20 The most common mistake in creating contract è The most common problem in creating contracts is forgetting to include the forming of associations. Particularly, when new instances are created, it is very likely that associations to several objects need be established. è Don’t forget to include all the associations formed and broken.
21 Example 1: End Sale Contract: End. Sale Operation: End. Sale () Cross References: Use Cases: Process Sale. Pre-conditions: There is a sale underway and all items have been entered. Post-conditions: § Sale. is. Complete became true. (attribute modification)
22 Example 2: Make Payment Contract: Make. Payment Operation: Make. Payment (amount: Number or Quantity) Cross References: Use Cases: Process Sale. Pre-conditions: There is a sale underway and all items have been entered. Post-conditions: § A Payment instance p was created. (instance creation) § p. amount. Tendered was set to amount. (attribute modification) § p was associated with the current Sale. (association formed) § The current Sale was associated with the Store; to add it to the historical log of completed sales. (association formed)
23 Example 3: Start Up Contract: Start. Up Operation: Start. Up () Cross References: Use Cases: Process Sale. Pre-conditions: None. Post-conditions: § A Store, POST, Product. Catalog and Product. Specifications have been created. (instance creation) § Product. Catalog was associated with Product. Specifications. (association formed) § Store was associated with Product. Catalog. (association formed) § Store was associated with POST. (association formed) § POST was associated with Product. Catalog. (association formed)
24 Summary è Contracts describe detailed system behavior in terms of state changes to objects in the Conceptual model after a system operation. è Contracts have sections of Operations, Cross references, Preconditions and Postconditions are the most important section. è Postconditions describe changes in the state of objects in the Conceptual model.
- Slides: 24