Contracts and
Contracts and
UML interaction diagrams
UML interaction diagrams
Lecture 4
Lecture 4
Hoa Sen University 1
Agenda
Agenda
System sequence diagram
Operation Contract
On to Object design
–
Interaction diagrams
Sequence diagrams
Communication diagrams
Hoa Sen University 2
System Sequence Diagram
System Sequence Diagram
Hoa Sen University 3
Operation:
enterItem(…)
Post-conditions:
- . . .
Operation Contracts
Sale
System Sequence Diagrams
make
NewSale()
system
events
Cashier
Process
Sale
: Cashier
use
case
names
system
operations
Use Case Diagram
Vision
Supplementary
Specification
Glossary
parameters and
return value details
starting events to design for
Process Sale
1. Customer
arrives
2. Cashier
makes new
sale.
3.
What is System Sequence Diagram
the ":" and underline imply an instance, and are explained in a
later chapter on sequence diagram notation in the UML
a message with
parameters
it is an abstraction
representing the
system event of
entering the
payment data by
some mechanism
description, total
return value(s)
associated with the
previous message
an abstraction that
ignores presentation
and medium
the return line is
optional if nothing is
returned
total with taxes
change due, receipt
makeNewSale
[ more items ]
loop
Use Cases and SSDs
Use Cases and SSDs
Hoa Sen University 6
: Cashier
:System
System events should be expressed at the abstract level
of intention rather than in terms of the physical input
device
Hoa Sen University 7
enterItem(itemID, quantity)
scan(itemID, quantity)
: Cashier
worse name
better name
:System
Iterative and Evolutionary SSDs
Iterative and Evolutionary SSDs
Do not create SSDs for all scenarios
(remember agile style)
SSDs are part of the Use-Case Model
–
Visualization of the interactions implied in the
use cases scenarios
Hoa Sen University 8
Operation Contract
Operation Contract
Hoa Sen University 9
Operation:
enterItem(…)
Post-conditions:
- . . .
Operation Contracts
Sale
System Sequence Diagrams
make
NewSale()
system
events
Cashier
Process
Sale
: Cashier
use
case
names
system
operations
Use Case Diagram
Vision
Supplementary
Specification
Glossary
starting events to
design for, and
more detailed
requirements that
must be satisfied
by the software
Process Sale
1. Customer
arrives
2.
3. Cashier
–
sli was associated with the current Sale (association formed).
–
sli.quantity became quantity (attribute modification).
–
sli was associated with a ProductDescription, based on itemID match
(association formed).
Hoa Sen University 10
Contract definition
Contract definition
A description of each section in a contract is shown in the following
schema.
Operation: Name of operation, and parameters
Cross References: Use cases this operation can occur within
Preconditions: Noteworthy assumptions about the state of the
system or objects in the Domain Model before
execution of the operation. These are non-
trivial assumptions the reader should be told.
Postconditions: This is the most important section. The state of
objects in the Domain Model after completion
of the operation. Discussed in detail in a
following section.
Hoa Sen University 11
Contract procedure
Contract procedure
these input system events
invoke system operations
the system event enterItem
invokes a system operation
called enterItem and so forth
this is the same as in object-
oriented programming when
we say the message foo
invokes the method (handling
operation) foo
[ more items ]
loop
:System
Process Sale Scenario
Process Sale: makeNewSale
Process Sale: makeNewSale
Contract CO1: makeNewSale
Operation: makeNewSale()
Cross References: Use Cases: Process Sale
Preconditions: none
Postconditions:
–
A Sale instance s was created (instance creation).
–
s was associated with a Register (association formed).
Hoa Sen University 15
Static vs. dynamic modelling
Static vs. dynamic modelling
Dynamic models help design the logic,
the behavior of the code or the method
bodies
–
Sequence diagram, communication diagram
Static models help design the definition
of packages, class names, attributes, and
method signatures
–
UML class diagram
Hoa Sen University 16
Use-Case Realization
Use-Case Realization
“…describes how a particular use case is
realized within the design model, in terms
of collaborating objects” [RUP]
Individual scenarios are realized
Hoa Sen University 17
Use case -> System events -> System sequence diagram ->
System operation contracts -> Interaction diagrams -> Design classes
System operation
System operation
Hoa Sen University 18
create
: Register
enterItem( )
: ProductCatalog
desc = getProductDesc( itemID )
. . .
UI LAYER
Window objects
or
GUI widget objects
or
Web control objects
. . .
DOMAIN LAYER
Design makeNewSale
Design makeNewSale
Choosing the controller class
–
A façade controller is satisfactory if there are
only a few system operations
–
Use Register here.
Creating a new Sale
–
Register create Sale
–
Sale create a collection to store
SalesLineItems
Operation: enterItem(itemID : ItemID, quantity : integer)
Cross References: Use Cases: Process Sale
Preconditions: There is an underway sale.
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 ProductDescription, based on itemID match
(association formed).
Hoa Sen University 22
Design enterItem
Design enterItem
Choosing controller class
Display item description and price (ignore
at this stage)
Create a new SalesLineItem
Finding a ProductDescription
Visibility to ProductCatalog
SalesLineItem
quantity : Integer
ProductCatalog
getProductDesc( )
ProductDescription
description : Text
price : Money
itemID: ItemID
1
*
1
*
Register
enterItem( )
Sale
isComplete : Boolean
time : DateTime
makeLineItem( )
1
1
1
catalog
currentSale
descriptions