Chapter 11
Chapter 11
Active
entry / action
A state may
expression
include a sub-
exit/ action expression
statechart
do / activity
include / submachine
itemSelected() / highlightItem()
entry / displayMenu
exit / hideMenu
do / playSoundClip
Exiting the state
triggers
While the object remains hideMenu()
in the Menu Visible
state, the activity causes a
sound clip to be played
© Bennett, McRobb and Farmer 2002 10
/assignManager();
Action-expression
assignStaff()
assigning manager Commissioned
and staff on object
creation authorized(authorizationCode)
[contract signed]
/setCampaignActive() Recursive transition
Statechart models any payment
for the class Active event that does not
reduce the amount due
Campaign campaignCompleted() to zero or beyond
/prepareFinalStatement()
Guard condition
ensuring complete
payment before Completed
entering Paid
paymentReceived(payment)
paymentReceived(payment)
[paymentDue – payment <= zero]
[paymentDue - payment > zero]
Paid
archiveCampaign()
/unassignStaff();
unassignManager()
© Bennett, McRobb and Farmer 2002 11
/assignManager();
assignStaff()
Commissioned
authorized(authorizationCode)
[contract signed]
/setCampaignActive()
A revised
statechart for Active
the class campaignCompleted()
Campaign /prepareFinalStatement()
paymentReceived(payment)
[paymentDue - payment < zero]
If the user
/generateRefund()
requirements were Completed
to change, so that
paymentReceived(payment)
an overpayment is [paymentDue - payment = zero] paymentReceived(payment)
now to result in the [paymentDue – payment > zero]
automatic
generation of a
Paid
refund, a new
archiveCampaign()
transition is added /unassignStaff();
unassignManager()
© Bennett, McRobb and Farmer 2002 12
Nested Substates
The transition from the initial pseudostate
The Active state of symbol should not be labelled with an
Campaign showing nested event but may be labelled with an action,
though it is not required in this example
substates
Active
extendCampaign() advertsApproved()
/modify Budget() /authorize()
Advert Preparation
campaignCompleted()
/prepareFinalStatement()
include / Running
Hidden
decomposition
indicator icon
Running
extendCampaign() advertsApproved()
/modify Budget() Advert Preparation /authorize()
confirmSchedule()
Running Adverts Scheduling
campaignCompleted()
/prepareFinalStatement()
Monitoring
surveyComplete()
Survey
Evaluation
runSurvey()
:CompleteCampaignUI *getClient()
startInterface()
selectClient()
showClientCampaigns()
listCampaigns() Active state
*getCampaignDetails()
completeCampaign()
completeCampaign()
campaignCompleted()
Completed state
authorized(authorizationCode)
[contract signed]
/setCampaignActive()
Initial extendCampaign() advertsApproved()
/modify Budget()
statechart Advert Preparation /authorize()
Campaign campaignCompleted()
/prepareFinalStatement()
class—a paymentReceived(payment)
behavioural [paymentDue - payment < zero]
/generateRefund() Completed
approach paymentReceived(payment)
[paymentDue - payment = zero] paymentReceived(payment)
[paymentDue – payment > zero]
Paid
archiveCampaign()
/unassignStaff();
unassignManager()
© Bennett, McRobb and Farmer 2002 23
/assignManager();
assignStaff()
Commissioned
authorized(authorizationCode)
[contract signed]
/setCampaignActive()
Active
Revised extendCampaign()
/modify Budget()
advertsApproved()
/authorize()
Advert Preparation
statechart
for the Running Adverts
confirmSchedule()
Scheduling
Campaign campaignCompleted()
/prepareFinalStatement()
class
paymentReceived(payment)
[paymentDue - payment < zero]
/generateRefund() Completed
paymentReceived(payment)
[paymentDue - payment = zero] paymentReceived(payment)
[paymentDue – payment > zero]
Paid
archiveCampaign()
© Bennett, McRobb and Farmer 2002 24
/unassignStaff();
unassignManager()
/assignManager();
assignStaff()
Commissioned
authorized(authorizationCode)
[contract signed]
/setCampaignActive()
Active
Monitoring
surveyComplete()
Final Survey
version of runSurvey()
Evaluation
Campaign Running
extendCampaign() advertsApproved()
campaignCancelled()
statechar /calculateCosts();
prepareFinalStatement()
/modify Budget()
Advert Preparation /authorize()
t Running Adverts
confirmSchedule()
Scheduling
campaignCancelled()
/cancelSchedule() campaignCompleted()
calculateCosts(); /prepareFinalStatement()
prepareFinalStatement()
Completed
paymentReceived(payment)
paymentReceived(payment)
[paymentDue - payment < zero] paymentReceived(payment)
[paymentDue - payment = zero]
/generateRefund() [paymentDue – payment > zero]
archiveCampaign()
© Bennett, McRobb and Farmer 2002 Paid 25
/unassignStaff();
unassignManager()
Life Cycle Approach
Consider the life cycles for objects of
each class
Events and states are identified directly
from use cases and from any other
requirements documentation that
happens to be available
First, the main system events are listed
Each event is then examined in order to
determine which objects are likely to
have a state dependent response to it
© Bennett, McRobb and Farmer 2002 26
Life Cycle Approach Steps
1. Identify major system events.
2. Identify each class that is likely to have a
state dependent response to these events.
3. For each of these classes produce a first-cut
statechart by considering the typical life
cycle of an instance of the class.
4. Examine the statechart and elaborate to
encompass more detailed event behaviour.