Upload
aulii
View
25
Download
2
Embed Size (px)
DESCRIPTION
Modelling dynamic information. So far we have seen: Use Case Diagrams – requirements capture, interface modelling Use Case Scripts – more detailed and with alternate, less common cases noted - PowerPoint PPT Presentation
Citation preview
State and Sequence Diagrams
Modelling dynamic information
So far we have seen:Use Case Diagrams – requirements capture,
interface modellingUse Case Scripts – more detailed and with
alternate, less common cases notedClass Diagrams – description of the structure of a
class and possibly its relationship with other classes
These are static descriptions of software
State and Sequence Diagrams
Dynamic Modelling
In order to model the dynamic (run-time) relationships we need different tools
The UML provides us with State Diagrams and Object Sequence Diagrams (OSD)
There are others...
State and Sequence Diagrams
State Diagrams
What do state diagrams describe?When things happenThe life-cycle of an instance (object)
How useful are they?Often but not always usedLogically links a Class Diagram to a State Diagram
– events are operations on classes in the Class Diagram
Clarifies the internal state and external behaviour of an object
State and Sequence Diagrams
State Diagram Elements
start point states end point(s)
transitions (labeled with events)
PaidUnpaidpay
createinvoice
destroyinvoice
State and Sequence Diagrams
State Diagram examples
A chess game classWhite takes the first turn, then turns alternateAfter any move “mate” or “stalemate” may occur
Black's turn
White's turn
Black wins
Draw
White wins
mate
mate
stalemate
stalematemove
move
State and Sequence Diagrams
State Change Events
A state describes a particular condition of an object for a period of time – it waits for an event to change state or to “fire”
Events can be of the following types:Change – occurs when a condition becomes true
i.e. a booleanCall/Signal – occurs when an object receives a call
for one of its operations (from another object or from itself)
Time trigger
State and Sequence Diagrams
Guards
Known as a guard conditionIt guards the transition i.e. the transition can
only take place if the guard condition evaluates to true
Guards are constraints on behaviourExample in Visio
State and Sequence Diagrams
Event Types
Kinds of eventsreceipt of a call on an operation - a messagereceipt of an explicit signal from another object - a
messagea condition becoming truepassage of a designated period of time
Basic semantics about event labelled transitions
events are triggers that activate state transitionsif an event occurs and guard is false then the event is
ignored (events are not stored)
State and Sequence Diagrams
Inside States
Three kinds of internal content for a stateThese represent the internal activities or state
activities that are executed in that stateEntry actionsExit actionsInternal transitions - do not cause a state change
All the above represent the operations for the class that is being modelled
State and Sequence Diagrams
How to find States
A state chart captures all the possible responses of a single object to all the Use Cases in which it is involved
So a cross reference of which of the Use Cases a class is involved in will give you possible states for an object of that class
The state chart can be seen as a description of all the possible life-cycles for an objectProvides a dynamic view of a class
State and Sequence Diagrams
Object Sequence Diagrams
OSDs depict a Use Case Script visually but also show the classes (objects) used in the script
They show the sequence of object interactionRead the Visio tutorials for detailed information
on the Sequence ChartThe next slides show example Sequence
Charts
State and Sequence Diagrams
Simple Example
Mary : HotelGuest
324 : Room fred : Cleaner hilton : Hotel Fred X : CleanerXMary X : Guest
1: leaving
2: I am vacating
3: clean me
4: clean room 324
5: done romm 324
6: you are clean
7: I am available
State and Sequence Diagrams
State and Sequence Diagrams
Sequence Diagrams
PurposeCaptures the
behaviour of a single use case - how messages are sent within a use case
Shows how objects interact with each other - show how they send and receive messages
Focuses on time
Name : Class
SyntaxObject
Time
message
State and Sequence Diagrams
Sequence Diagram
Example
Nokia : TelephoneSystem
Caller : Person Receiver : Person
1: pick up
2: dial tone
3: dial4: ring
5: ring notification
6: pick up
State and Sequence Diagrams
Sequence Diagram
Types of messagessimple
flat flow of control - control is passed without describing any details
synchronousnested flow of control - operation callhandling of the message is completed before the caller
resumes execution
asynchronousthere is no explicit return to the callerthe sender continues to execute after sending the
message without waiting for it to be handled
State and Sequence Diagrams
Sequence Diagram
ActivationTime during which object
performs an action either directly or through another object (subcontractor)
ReturnImplicit
Explicit
: A : B
1:
: A : B
State and Sequence Diagrams
Drawing an OSD
Select a Use Case for which you have a ScriptMake a list of classes which appear on that
script (you may have done this already if you have created a Class Diagram)
Use Visio to create a new Sequence DiagramDo the simple things first and build it upPlace the objects (classes) on the diagramThink about the order that you put them in
State and Sequence Diagrams
Drawing an OSD
When creating messages, for the first draft just use the simple message call shapeRefine to synchronous or asynchronous at the 2nd
draft
Finally, put the rectangle duration box (operation life) overlay onto the timeline for each object
Then review it and do a 2nd draft
State and Sequence Diagrams
Self-paced tutorial
Create a State Diagram in Visio for the third version of the example Soup Menu applicationHints: states include ingredient choice (three types) and action choiceWhat kind of transitions are there? - write down a listHints: remember that each transition is a flow from one state to anotherFinally, what events/actions are there for the transitions in your list?