Professional Documents
Culture Documents
Software Construction: State Chart & Activity Diagrams
Software Construction: State Chart & Activity Diagrams
Lecture 11
State Chart & Activity Diagrams
1
StateChart Diagram
Use Cases describe the requirements of the system
State
— The state of an object represents a period of time during which the object
satisfies some condition or waits for an event
Transition
— A state transition represents the response of an object to an event.
Process Sale
makeNewSale
WaitingForSale EnteringItems
(external system
events) enterItem
endSale
makePayment
WaitingForPayment
makeNewSale
WaitingForSale EnteringItems
enterItem
endSale
authorized
makeCashPayment
WaitingForPayment
Authorizing makeCreditPayment
Payment makeCheckPayment
A Sample Statechart
Exercise
Draw a state chart for the primary usecase
of your course project
StateChart Diagram
State-Independent objects
If an object always responds in the same way to an event, then
it is considered state-independent (modeless) with respect to
that event
The method will have no conditional logic
State-Dependent objects
React differently to events depending upon their state
StateChart Diagram
Common objects which are usually State-Dependent
Use Cases
The ProcessSale use case reacts differently to the endSale event
dependent of if sale is underway or not
Stateful sessions
Server side handling of web client applications
Server objects representing ongoing sessions or conversations with a
client
System
A class representing the overall application or system
POSsystem
StateChart Diagram
Common objects which are usually State-Dependent cont…
Windows
Paste operation is only valid if there is something to paste
Controllers
GRASP controller objects: Handle different events
Transactions
Sale, Payment, order; having many states and react to an event
dependent on their current state
Devices
TV, Microwave oven; react differently to a particular event
depending upon their current state (e.g. on, off button)
StateChart Diagram
Events Types
External events
Internal events
Temporal events
StateChart Diagram
Events Types
External Events
Also called system events
These are caused by something (e.g. an actor) outside our system
boundary
SSD’s illustrates External events
External events are generated to invoke the system operations to
respond to them
Example: Cashier presses enter item button, an external event
has occurred
StateChart Diagram
Events Types
Internal Event
Caused by something inside our system boundary
In terms of software, an internal event arises when a method is
invoked via a message or signal that was sent from another
internal object
Messages in interaction diagrams suggest internal events
Example
sale receives makeLineItem() message – an internal event has
occurred
StateChart Diagram
Events Types
Temporal Event
Caused by occurrence of a specific date and time or passage of
time.
In terms of software, a temporal event is driven by a real time
or simulated time clock
Example1: Suppose that after endSale operation occurs, a
makePayment operation must occur within 2 minutes,
otherwise the current sale is automatically cancelled
Example2: Transactions on ATM
StateChart Diagram
Interaction diagrams represent internal events
on hook
guard condition
Active
[valid subscriber]
Idle
PlayingDialTone Talking