copyright © hsiao-lan wei. 2003 all rights reserved design model interaction diagram
TRANSCRIPT
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved
Design Model
Interaction diagram
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 2
Elaboration Iteration 1
On to Object Design
(OOD)
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 3
Analysis and Design
Analysis—“what”
investigation of the problem and requirements
Design—“how”
description of a software solution
Requirements
Use cases
Constraints
Vocabulary
Objects
Architecture
Deployment
UI
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 4
Object-oriented Analysis and Design
Object-oriented analysis
– What are the domain objects?
•Described in a domain object model
Object-oriented design
– Describing the software solution in terms of collaborating objects, with responsibilities.
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 5
Transition to Design During requirements and analysis work, we
– “Do the right thing”
– Understand the domain
– Clarify and record the constraints and requirements
– Essentially ignore thinking about the design, and focus on understanding the problem.
– . . .
During design, we– “Do the thing right”
– Create a software (and hardware) solution that meets the wishes of the stakeholders.
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 6
From Requirements to Design
A set of requirements-oriented artifacts (and thought) inspire design-oriented artifacts.
Domain Model Use Case ModelSupplementary Specs
(Req list andattributes,. . . )
Software ArchitectureDocument
Design Model Data Model
. . .
. . .
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 7
Changing Hats
Until this time, we have been wearing an “investigator” hat, essentially ignoring what the solution should be.
– “Do the right thing”
Now, we take off the investigator hat, and put on our “designer” hats.
– “Do the thing right”
Of course, in the context of iterative development, we do this repeatedly.
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 8
Objectives of Interaction Diagrams
Learn how to create interaction diagrams to model use-case behavior.
Understand the similarities and differences between sequence and collaboration diagrams.
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 9
So Where Are We?
Discovered boundary, control, and entity classes
Assigned responsibilities to each class
Determined how to use these classes to realize use-case scenarios
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 10
What are Interaction Diagrams?
An interaction diagram is a graphical representation of interactions between objects
– It models the dynamic aspects of a system.
There are two kinds of interaction diagrams Sequence diagrams
Collaboration diagrams
Each provides a different view of the same interaction Sequence diagrams are time ordered
Collaboration diagrams may include may data flow
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 11
What is a Sequence Diagram? A sequence diagram shows object
interactions arranged in time sequence
The diagram shows
The objects participating in the interaction
The sequence of messages exchanged
A sequence diagram contains:
Objects with their “lifelines”
Messages exchanged between objects in ordered sequence
Focus of control(optional)
Sequence Diagrams
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 12
Review: The Anatomy of Sequence Diagrams
1: PerformResponsibility
Client Object Supplier Object
Message
:Client :Supplier
Focus of Control
This is a sample script.
Reflexive MessageObject Lifeline
1.1: PerformAnotherResponsibility
Hierarchical MessageNumbering
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 13
A sequence Diagram
: Register : Sale
makePayment(cashTendered)
makePayment(cashTendered)
: Paymentcreate(cashTendered)
an activation box showingthe focus of control
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 14
What Is a Collaboration Diagram?
A collaboration diagram emphasizes the organization of the objects that participate in an interaction.
The collaboration diagram shows
– The objects participating in the interaction.
– Links between the objects.
– Messages passed between the objects.
Collaboration Diagrams
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 15
Sample Collaboration Diagram
1: makePayment(cashTendered)
1.1: create(cashTendered)
: Register :Sale
:Payment
makePayment(cashTendered)
creation indicated with a"create" message
direction of message
first message
instance
first internal message
link line
parameter
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 16
Creating Interaction Diagrams
Use cases are examined to determine the scenarios
Additional information may be needed to complete the scenario
Details of the system that have been omitted from the use case
Example : John enters the student ID number 369523449
Question : Where is the id number entered
Answer: Some sort of form is needed
• Registration form added
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 17
Sequence and Collaboration Diagram Similarities
Semantically equivalent
– Can convert one diagram to the other without losing any information
Model the dynamic aspects of a system Model a use-case scenario
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 18
Sequence and Collaboration Diagram Differences
Collaboration diagrams
– Show relationships in addition to interactions
– Better for visualizing patterns of collaboration
– Better for visualizing all of the effects on a given object
– Easier to use for brainstorming sessions
Sequence diagrams
– Show the explicit sequence of messages
– Better for visualizing overall flow
– Better for real-time specifications and for complex scenarios
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 19
Common interaction diagram notation
Classes and instances
Sale :Sale s1: Sale
class instance named instance
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 20
Basic Sequence Diagram Notation(1/5) Links
– Sequence diagrams do not show links Messages
– Message expression between objects is on an arrowed line.
Focus of control and activation boxes: Register : Sale
msg2()
msg3()
msg1()
msg4()
msg5()
: Register
msg1()
clear()
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 21
Basic Sequence Diagram Notation(2/5)
Creation of instances Object lifelines
: Register : Sale
makePayment(cashTendered) : Paymentcreate(cashTendered)
authorize()
note that newly createdobjects are placed at theircreation "height"
an object lifeline shows the extent ofthe life of the object in the diagram
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 22
Basic Sequence Diagram Notation(3/5) Conditional messages
Mutually exclusive conditional messages
: B: A
[ x < 10 ] calculate()message1()
: C
[ x > 15 ] calculate()
: Bar: Foo
[ color = red ] calculate()message1()
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 23
Basic Sequence Diagram Notation(4/5) Iteration for a single message
Iteration of a series of messages
: Simulator : Random
* [i:=1..N]: num := nextInt()
runSimulation()
: Simulator : Random
hours := nextInt()
runSimulation()
: Programmer
work( hours )
* [i:=1..N]
eat()
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 24
Basic Sequence Diagram Notation(5/5) Iteration over a collection (multiobject)
Messages to class objects
: Sale
* : st := getSubtotal()
t := getTotal()
:SalesLineItem:SalesLineItem
: Foo
list := synchronizedList( aList)message1()
java.util.Collections
not underlined,therefore a class
message to class, or astatic method call
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 25
Basic Collaboration Diagram Notation(1/7)
Links
– A connection path between two objects
– Indicates some form of navigation and visibility
– Multiple messages and messages both ways can flow along the same single link
1: makePayment(cashTendered)
2: foo()
2.1: bar(): Register :Sale
link line
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 26
Basic Collaboration Diagram Notation(2/7)
Messages
– A sequence number is added to show the sequential order of messages
– Small arrow with each message indicates the direction of the message
– Messages to “self”
1: msg2()2: msg3()3: msg4()
3.1: msg5(): Register :Sale
all messages flow on the same link
msg1()
: Register
msg1()
1: clear()
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 27
Basic Collaboration Diagram Notation(3/7)
Creation of instances
1: create(cashier)
: Register :Sale {new}
create message, with optional initializing parameters. This willnormally be interpreted as a constructor call.
<<create>>1: make(cashier)
: Register :Sale {new}
if an unobvious creation message name is used, themessage may be stereotyped for clarity
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 28
Basic Collaboration Diagram Notation(4/7)
Message number sequencing
– The first message is not numbered.
– Nesting is denoted by prepending the incoming message number to the outgoing message number
2: makeLineItem(ps, qty)enterItem(id, qty)
1: ps := getSpecification(id)
1.1: ps := get(id)
1.3 [not in specs & specs not full] : put( id, ps)
:Register :Sale
:ProductCatalog
:ProductSpecification
UML notation: note theconditional message syntax
: LocalProducts
IProductsAdapter
1.2 [ not in specs ]:ps := getSpecification(id)
specs
continued in anotherdiagram
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 29
Basic Collaboration Diagram Notation(5/7)
Conditional messages
1 [ color = red ] :calculate(): Foo : Bar
message1()
conditional message, with test
1a [test1] : msg2()
:ClassA :ClassB
:ClassC
1a.1:msg3()
msg1()
:ClassD
1b [not test1] : msg4()
1b.1: msg5()
:ClassE
2: msg6()
unconditional aftereither msg2 or msg4 1a and 1b are mutually
exclusive conditional paths
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 30
Basic Collaboration Diagram Notation(6/7)
Iteration
Iteration over a collection (multiobject)
1 * [i:=1..N]: num := nextInt(): SimulatorrunSimulation() : Random
iteration is indicated with a * and an optionaliteration clause following the sequence number
1 *: st :=getSubtotal(): Salet := getTotal()
double box indicates a multiobject (collection)
for example, a List object containing manySalesLineItem objects
*:SalesLineItem
:SalesLineItem
these two * symbols used together implyiteration over the multiobject and sending thegetSubtotal message to each member
Copyright © Hsiao-Lan Wei. 2003 All Rights Reserved 31
Basic Collaboration Diagram Notation(7/7)
Messages to a class object
list := synchronizedList( aList ): InstanceOfFoo java.util.Collections
msg1()
not underlined,therefore a class
message to class, or astatic method call