University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 1 object states an...
-
Upload
domenic-gilbert -
Category
Documents
-
view
214 -
download
1
Transcript of University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 1 object states an...
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 1
object states
an object state is a condition or situation during the life of an object during which it:
• satisfies some condition• or performs some activity• or waits for some event
the current state of an object determines how it will behave
the current state of an object is determined by:• current values of attributes• and current links with other objects
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 2
an object moves from one state to another by a transitionwhich is either:
• triggered by an event • or the state simply finishes (triggerless transition)
statechart diagram is a model of:• all the states and object can have• the events that cause transitions• all possible responses to all use cases
Not all messages an object can receive will alter its state,in particular messages that do not cause changes to attributes or links(e.g. “get” and “query”)
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 3
events may trigger action by actor or object
time end of designated time periodafter [time expression]
change when a condition becomes truewhen [Boolean expression]
signal receipt of an asynchronous communication signal
call receipt of call for an operation (synchronous)from self or other object
events
event-signature [guard-condition] / return-value:= action-expression
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 4
event-signature [guard-condition] / return-value:= action-expression
event-signature operation (parameter-list)guard-condition Boolean expressionaction expression operation (paramter-list)
an example showing multiple actions. . .leftMouseDown(location) [validItemSelected] / menuChoice:= pickMenuItem(location); menuChoiceHighlight ( )
three more examples . . .• /assignManager ( ) ; assignStaff ( )• authorization (authorizationCode) [contract signed] / setCampaignActive ( )• paymentReceived ( payment) [paymentDue – payment <= zero] /
A[B]/Cif told to do A and B is true, then also do C, causing a state changeif told to do A and B is false, then don’t do C and state does not changeif no guard condition, then state always changes
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 5
state name
event [guard condition] /action expression
menu visible
itemSelected ( ) / highlightItem ( )entry / displayMenu ( )exit / hideMenu ( )do / playSoundClip ( )
event [guard condition] / action expression
labels and notation
event-signature [guard-condition] / return-value:= action-expression
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 6
initial state
when [discountStartDate <=currentDate]
when [discountFinishDate <=currentDate]
after [1 year]
discountRate( ) pending
active
lapsed
on creation, theobject moves
immediately into thefirst named state
the event that createsthe object
cannot leave finalstate once it has been
entered
change events
elapsed-time event
transition
basic notation
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 7
when [discountStartDate <=currentDate]
when [discountFinishDate <=currentDate]
after [1 year]
discountRate( ) pending
active
lapsed
<<entity>>discountRate
ratediscountStartDatediscountFinishDate
createDiscountRate ( )assignLatestDiscountRate ( )
statechart for the class DiscountRate
createDiscount-Rate ( )
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 8
enters hospital
checks in
[diagnosis = healthy]
entering
admitted
released
underobservation
[diagnosis = unhealthy]
[> 2 weeks]
[diagnosis = healthy]
hospital patient
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 9
order is created
customersubmits order
order sent for creditauthorization
pending
ordered
credit check denied
customer withdrawsorder request
[authorization= approved]
[authorization= denied]
receivedshippedplacedorder
sent tocustomer
customeraccepts
shipmentorder is closed
online order
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 10
reserve (medium type) / update number reserved
available
movie title
<<PK>> movieCode : StringmovieTitle : Stringdirector : StringinStock : Boolean
in stock
reserved
not in stock
ordered
not reserved
[no more reserved]
order item (quantity) [insufficient stock]
replenish stock (quantity)
return item (quantity / add quantity (no items)
rent out (quantity) / subtract item (last item)
put on shelf(quantity)
order item(quantity)
video store – movie title
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 11
cancelled ready to ship
filled
stock available[ship date now][canceled]
[canceled]
ship [accepted]
new order
future order
back orderstock not available
stock available [ship date in future]
stock available [ship date in future]
pending
online order
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 12
initializing
command
modeling the lifetime of an object
idle
active
entry / setAlarmexit / clearAlarm
checking
waiting
callingentry/callCenter ( )
after (10 seconds) /selfTest
alarm ()
clearattention
attention
alarm system
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 13
idle
transmitting
sendFax
ringingreceiving
entry /pickUpexit / disconnect
error / printReport
hangUp
connected
cleaning up
processing
headerOK
checkSumOK
example of nested states within a composite state and triggerless transitions
fax machine
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 14
name of state
name of substate 1
name of substate 2
concurrent substates
in this example,either transition T1 or T2can cause the object to leave any of states A1, A2, A3 or B1, B2, B3
and until either T1 or T2occurs, the object remainsin substate 1 and substate 2
A1 A2
A3
B1 B2
B3
T1 T2
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 15
when developing state charts . . .
what are the major system events?
what objects are affected by these events?(state charts are created)
what alternate scenarios exist?(state charts are enhanced)
are the state charts consistent with all use cases,collaboration and sequence diagrams?
(state charts are corrected if necessary)
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 16
when checking statecharts . . .
every event appears as an incoming message for the appropriate object in the right interaction (sequence or collaboration) diagram? corresponds to an operation on the appropriate class?
every action appears as an operation in that object’s class?
every outgoing message corresponds to an operation in another class?
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 17
Menu Visible
itemSelected() / highlightItem() entry / displayMenu exit / hideMenu do / playSoundClip
example: Menu Visible state for a DropDownMenu object
Entry action causes the menu to be displayed
Event itemSelected() triggers the action
highlightItem()
Exiting the state triggers
hideMenu()While the object remains in the Menu Visible state, the activity causes a sound clip
to be played
University of Toronto at Scarborough © Kersti Wain-Bantin CSCC40 state charts 18
Synchronized Concurrent Threads.
Synchronization bar
Explicitly showing how an event triggering a transition to a state with nested concurrent states causes specific concurrent substates to be entered
Shows that the composite state is not exited until both concurrent nested statecharts are exited