W12-14 BehavioralModeling
W12-14 BehavioralModeling
AC3010
1
Part 2: System analysis
Analysis
Requirements
determination
Structural modeling
Behavioral modeling
3
Chapter syllabus
5
7.1. Behavior Models
6
7.2. Interaction Diagrams
7
Sequence Diagrams
8
Sequence Diagrams
• Sequence diagrams illustrate the objects that participate in a use case and the
messages that pass between them over time for one use case.
• Primary goals:
• Allocate behavior to objects/classes
• Show in detail how objects/classes interact with each other over the lifetime of the use case
• Finalize the distribution of operations among classes
• Sequence diagram shows the design at a much more concrete and detailed view
• It may show additional infrastructure objects, details of persistence storage mechanisms
etc. depending on the architecture of the proposed system.
9
Sequence Diagram notation
10
Type of messages
• Synchronous message
• An operation call.
• The sender object transfers message to the receiver object, then pauses to
wait for the receiver object to return control.
• The receiver object performs the requested operation, if necessary, can
transfer control to another object and when the operation is completed
returns control to the sender object, possibly with a response result.
• The return message can be explicitly represented by the dashed arrow or can
be omitted, since it is the default at the end of the operation.
• Asynchronous message
• Just sending of a signal/operation call.
• The message enters the receiver's queue.
• The sender continue his work without waiting for the results
• The receiver performs an action and may also return a message to the sender.
But if there is a return, it must be expressed explicitly.
11
Type of messages
• Lost message:
• Known the sender, but don’t known the receiver
• Receiver is out of description scope, or this is a distribution.
• Found message:
• Know the receiver, but don’t known the sender
• Sender is out of description scope
12
Sequence Diagram Building
• There’s a direct link between each use case, its robustness diagram, and the
sequence diagrams
• The process of drawing the robustness diagram can rewrite the use case => use case
text should be complete, correct, detailed, and explicit.
• Draw a sequence diagram for every use case, with both basic and alternate
courses on the same diagram
• Map use case text to the messages on the sequence diagram
• Assign operations to classes while drawing messages and review class
diagrams frequently
13
Sequence Diagram Building
14
Sequence Diagram Steps
Decision-making !
16
CASE STUDY: Write Customer Review sequence diagram
17
CASE STUDY
18
CASE STUDY
“ a pure OO version”
19
CASE STUDY
• Can be extended
• Tie the design closely with the
implementation details of the
target framework before begin
coding
Spring Framework
“ a framework
dependent version”
20
Sequence Diagram Building
• Keep updating and refining the static model (the class diagrams)
• These detailed class diagrams should use the same elements as on the sequence
diagrams
• When assigning a message on the sequence diagram (the dynamic model), an
operation is automatically added to the appropriate class in the static model.
• Update the use case text if needed
21
CASE STUDY
22
• Prefactored static model
23
Quiz
Figure out the errors and then draw the corrected diagram
• Question 1
not matching
wrong
caller
24
Quiz
• Question 1
25
Quiz
Figure out the errors and then draw the corrected diagram
• Question 2: from Create New Book use case
No data validation
26
Quiz
• Question 2
27
Quiz
• Question 3
Edit Shopping Cart use
case
+ Begin/end problem
+ Where is customerID?
-> missing Customer
Account corresponding to
this Shopping Cart,
Customer Session
corresponding to this
Customer Account
+ Wrong caller
+ Not need
redundant
28
Quiz
• Question 3
29
Other Sequence Diagrams Reference
• Object
https://www.uml-diagrams.org 30
Other Sequence Diagrams Reference
• Overlapping
execution
• Runtime constraint
https://www.uml-diagrams.org 31
Other Sequence Diagrams Reference
• Callback
32
Other Sequence Diagrams Reference
• Combined fragment
33
Other Sequence Diagrams Reference
https://www.uml-diagrams.org 34
Other Sequence Diagrams Reference
https://www.uml-diagrams.org 35
Collaboration/Communication Diagrams
36
Collaboration/Communication Diagrams
37
Communication Diagrams
38
Communication Diagrams
• Example
39
Communication Diagrams
• Example
40
Collaboration Diagrams vs. Sequence Diagrams
• Object
• Sequential Loop
• Concurrent Loop
https://www.uml-diagrams.org 42
7.3 State Machine Diagrams
43
7.3 State Machine Diagrams
• Some of the objects are quite dynamic: can pass through a variety of states
over their life time
• The dynamic model that shows the different states through which a single
object passes during its life in response to events, along with its responses
and actions
• Typically not used for all objects
• Just for complex ones to further define them and to help simplify the design of
algorithms for their methods
44
7.3 State Machine Diagrams
• When ?
• To help understand the dynamic aspects of a single class
• How its instances evolve over time
45
Behavioral State Machine elements
Behavioral State Machine
48
Guidelines for Creating Behavioral State Machines
1. Create a behavioral state machine for objects whose behavior changes based
on the state of the object.
2. To adhere to the left -to-right and top-to-bottom reading conventions, the
initial state should be drawn in the top left corner of the diagram and the final
state should be drawn in the bottom right of the diagram.
3. Names of the states are simple, intuitively obvious, and descriptive.
4. Question black hole and miracle states. Black hole states, states that an object
goes into and never comes out of, most likely are actually final states. Miracle
states, states that an object comes out of but never went into, most likely are
initial states.
5. Be sure that all guard conditions are mutually exclusive.
6. All transitions should be associated with a message and operation.
When to Use State Diagrams
51
Other State Machine Diagrams Reference
• Choice
• Choice based on guards applied to the value inside diamond.
• Fork
• Fork splits transition into two transitions.
• Join
• Join merges transitions into single transition.
https://www.uml-diagrams.org 52
Other State Machine Diagrams Reference
55
56