Use Case Model Operation Contracts

22
Use Case Model Operation Contracts Chapter 11 Applying UML and Patterns Craig Larman

description

Use Case Model Operation Contracts. Chapter 11 Applying UML and Patterns Craig Larman. Objectives. Create contracts for each system operation. UP Artifacts. Domain Model. Vision. Use Case Model. Use Case Text. Glossary. Operation Contract. System Sequence Diagrams. - PowerPoint PPT Presentation

Transcript of Use Case Model Operation Contracts

Page 1: Use Case Model  Operation Contracts

Use Case Model Operation Contracts

Chapter 11Applying UML and Patterns

Craig Larman

Page 2: Use Case Model  Operation Contracts

2

Objectives Create contracts for each system

operation

Page 3: Use Case Model  Operation Contracts

UP Artifacts

Page 4: Use Case Model  Operation Contracts

4

Unified Process Artifacts

Business Model

Requirements

Design

Domain Model

Use Case Model

Operation Contract

Use Case Text

System Sequence Diagrams

Interaction Diagrams

Supplementary Specifications

Vision

Glossary

See Figure 6.1 in text for more detail

Page 5: Use Case Model  Operation Contracts

5

Why Write Operation Contracts Use cases are the primary mechanism

in the UP to describe system behavior They are usually sufficient.

Sometimes a more detailed description of system behavior has value.

Contracts for operations can help define system behavior.

Page 6: Use Case Model  Operation Contracts

6

Domain Model And Contracts A Domain Model is a visual

representation of conceptual classes or real-world objects in a domain of interest.

Contracts describe detailed system behavior in terms of state changes to objects in the Domain Model, after a system operation has executed.

Page 7: Use Case Model  Operation Contracts

7

Keep it Agile In many, or even most software

development projects, operation contracts may be unnecessary

Use them only when necessary to add additional detail and understanding

Page 8: Use Case Model  Operation Contracts

8

System Operations andthe System Interface Contracts may be defined for system

operations Operations treat the system as a black

box which uses its public interface to handle incoming system events.

System operations can be identified by discovering these system events.

The entire set of system operations, defines the public system interface, views system as single component/class

Page 9: Use Case Model  Operation Contracts

9

Example Contract: enterItem

Operation: enterItem(itemID : ItemID,quantity : integer)

Cross References: Use Cases: Process SalePreconditions:There is a Sale Underway.Postconditions: -A SalesLineItem 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 ProductSpecification, based on itemID match (association

formed)

Contract CO2: enterItem

Page 10: Use Case Model  Operation Contracts

10

Contract Sections

Operation: Name Of operation, and parameters.Cross References: (optional) Use cases this

can occur within.Preconditions:Noteworthy assumptions about the

state of the system or objects in the Domain Model before execution of the operation.

Postconditions: -The state of objects in the Domain Model after completion

of the operation.

Page 11: Use Case Model  Operation Contracts

11

Postconditions Five changes in Domain Model include

1. instance created 2. instance destroyed 3. association formed 4. association broken, 5. attribute value modified.

Postconditions are declarations about the Domain Model objects that are true when the operation has finished

Page 12: Use Case Model  Operation Contracts

12

Naming Postconditions Express postconditions in past tense, as

they describe a previous state change

-A SalesLineItem 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 ProductSpecification, based on itemID match (association formed)

Page 13: Use Case Model  Operation Contracts

13

Writing Contracts Leads to Domain Model Updates New conceptual classes, attributes, or

associations in the Domain Model are often discovered by writing contracts

Change the Domain Model as you make new discoveries while thinking through the operation contracts

Page 14: Use Case Model  Operation Contracts

14

Contracts vs. Use Cases The use cases are the main repository

of requirements for the project. Provide most or all of the detail

necessary to know what to do in design. If the details and complexity of required

state changes are awkward to capture in use cases, then write operation contracts.

Page 15: Use Case Model  Operation Contracts

15

Too Many Contracts If…

If a team is making contracts for every system operation: the use cases are poorly done, or there is not enough collaboration or access to a

subject matter expert, or the team is doing too much unnecessary

documentation

Page 16: Use Case Model  Operation Contracts

16

Guidelines: Contracts To make contracts:

Identify system operations from the SSDs For system operations that are complex and

perhaps subtle in their own results, or which are not clear in the use case, construct a contract.

To describe the postconditions, use ONLY: instance creation and deletion attribute modification associations formed and broken

Page 17: Use Case Model  Operation Contracts

17

The Most Common Mistake In Creating Contracts The most common problem in creating

contracts is forgetting to include the forming of associations.

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.

Page 18: Use Case Model  Operation Contracts

18

Contracts, Operations, and the UML

The UML formally defines operations. To quote: An operation is a specification of a

transformation or query that an object may be called to execute [RJB99]

An operation is an abstraction, not an implementation. By contrast, a method (in the UML) is an implementation of an operation.

Page 19: Use Case Model  Operation Contracts

19

Contracts, Operations, and the UML

UML operation has signature (name and parameters), and a specification

Specification describes the effects produced by executing the operation (the postconditions)

UML operation specification does not show an algorithm or solution

It only shows state changes or operation effects

Page 20: Use Case Model  Operation Contracts

20

Operation ContractsWithin the UP A pre- and postcondition contract is a

well-known style to specify an operation.

In UML, operations exist at many levels, from top level classes down to fine-grained classes.

Operation specification contracts for the top level classes are part of the Use-Case Model.

Page 21: Use Case Model  Operation Contracts

21

Summary Contracts describe detailed system

behavior in terms of state changes to objects in the Domain Model after a system operation.

Contracts have sections of Operations, Cross references, Preconditions and Postconditions. Postconditions are the most important

section. Postconditions describe changes in the

state of objects in the Domain Model.

Page 22: Use Case Model  Operation Contracts

22

Summary Only write contracts for the most difficult

to understand or complicated system operations. Dr. Bob’s Rule of Thumb: If an operation

has Postconditions, write a contract Domain Model state changes include

instances created, associations formed or broken, and attributes changed.