Title: CPSC333 SENG311: Foundations Principles of SE
1CPSC333 / SENG311 Foundations / Principles of SE
- Events and State Diagrams
2Agenda
- Current position in development process
- Events
- State diagrams
3Main processes of the team assignment
requirements analysis
design process
coding
testing
requirements document
problem description
design document
Used technique Use cases
Used technique UML component diagrams, UML class
diagrams, UML state diagrams UML sequence
diagrams, UML activity diagrams
Used language Java
4Refined design processes of the team assignment
requirements analysis
design process
coding
testing
create system architecture
specify component interfaces
develop component design
Used technique UML component diagrams
Used technique UML class diagrams, UML state
diagrams UML sequence diagrams, UML activity
diagrams
5State diagram
- Shows the behavior of one object of a single
class - shows all possible states of this object
- shows how the objects state changes as a result
of messages it receives, or in response to
internal and external events - narrowly focused, fine-grained
- Other names
- State transition diagram
- Harel diagram (statecharts)
6Object states
- State set of values that describe an object
(its condition/situation) at a specific moment in
time - State is determined based on the attribute values
overdrafted
states
ok
7Events, signals and exceptions
- Event occurrence in time and space
- External passed between system and actors
- Internal passed between objects of the system
- Four kinds of events
- Call event
- Time event
- Change event
- Signal event asynchronous event communicated
between instances
8Call events
- Call event dispatch of operation
- Call event is synchronous
9Time and change events
- Time event after time expression
- after 2 seconds
- after 1 ms since idle
- after(5 minutes) / take the egg from the pot
- Change event when condition
- when time 400am
- when altitudelt1000
- when (1200AM) / goForLunch()
10Change and Time Events - Example
/ turn around
11Signals
- Modeled as stereotyped classes
- Can have attributes
ltltsendgtgt
12Signal support inheritance
13Exceptions
- In UML kinds of signals to denote an erroneous
condition - can be raised by operations
ltltsendgtgt
ltltsendgtgt
ltltsendgtgt
14Self-Exercise
- Develop a state diagram for class
MachineControl that may execute a self test in
parallel to a normal cycle of reading a sensor,
evaluating the sensor values and opening a valve.
The MachineControl can be initializing, running
and terminating.
15State changes (1)
- States may be changed when an event occurs
- State transition relationship indicating a state
change - atomic (i.e. non-interruptible)
overdrafted
deposit(sum)
withdraw(sum)
ok
16State changes (2)
- Events Messages or signals received
- Events may or may not change the state
- Self-transition
deposit
overdrafted
withdraw
withdraw
deposit
ok
17State diagram notation (1)
- Activity Can take longer and be interrupted
- Action Occur quickly
- quickly non-interruptible
- entry an action that is performed on entry to
the state - exit an action performed on exiting the state
- do an ongoing activity performed while in the
state (example display window) - on an action performed as a result of a specific
event - Different from self-transition
State name
state variable(s)
entry / entry-action
do / activity-A
event1(aT)exp action1
eventn(aT)exp actionn
exit / exit-action
18State diagram notation (2)
Event(arguments)condition/action
State-A
State-B
- Event significant occurrence that has a location
in time and space - triggers the transition
- signals, calls, passing of time, change in state
- Guard condition
- Transition only occurs when guard evaluates to
true - Guards of transition exiting one state are
mutually exclusive - Action Processes considered to occur quickly and
are not interruptible - Each part can be omitted!
19State diagram notation (3)
Event(attribute)
State-B
Initial state
Start State
End State
- Start state
- No event triggers allowed
- branch conditions allowed
- may not remain in start states
- End state
- Top level end state terminates a state machine
20Example of Statechart Diagrams Order Management
21State transitions for an order
Event
not all items checked / get next item
Item received some
items not in stock
Action
All items checked some
items not in stock
Checking
/ get first item
Waiting
do check item
All items checked
Item received all items
all items available
available
Guard
Dispatching
Delivered
Delivered
do initiate delivery
22Problem Cancel the order
- Want to be able to cancel an order at any time
- Solutions
- Transitions from every state to state cancelled
- Superstate and single transition
23Transitions to cancelled
not all items checked / get next item
Item received some
items not in stock
All items checked
some items not in stock
Checking
/ get first item
Waiting
do checkitem
Item received all
items available
All items checked
all items available
cancelled
cancelled
Dispatching
cancelled
do initiate delivery
Cancelled
Delivered
Delivered
24State diagram notation (4)
Superstate
Event A
State-A
State-B
State-A
State-B
Event C
Event B
Composite state Sequential substates
25Superstate / Substates
Active
not all items checked / get next item
Item received some
items not in stock
All items checked some
items not in stock
Checking
/ get first item
Waiting
do checkitem
cancelled
Cancelled
Item received all
All items checked
items available
all items available
Delivered
Dispatching
Delivered
do initiate delivery
26State diagram notation (5)
Superstate
Event A
State-A
State-B
State-A
State-B
H
History state Start with the last substatethat
was active prior to leaving the composite state
Event C
Event B
27Example of Statechart DiagramsStates of a
hockey game
28Hockey example with superstate
Normal
time is up tie
shootout
playing
Fighting
penalty
face off
time is uo win
end of game
break
29Some remarks
- Statechart diagrams DO NOT HAVE TO refer to
classes or objects, they can also refer to
subsystems etc - However, often classes are the most widely use of
statechart diagrams...
30Some remarks
- Only one initial state may occur (directly)
within a composite state - End state represents completion of a composite
- End state triggers transition with composite as
source
31Orthogonal components and concurrency
- Unrelated or multiple components of
objects combinatorial number of states - Example Car states
- engine (started, stopped)
- doors (open, closed)
- What happens when we add one component?
- seat belt (fastened, open)
4 car statesstarted_open started_closed stopped_
open stopped_closed
8 car statesstarted_open_open
started_open_fastened started_closed_open
started_closed_fastened stopped_open_open
stopped_open_fastened stopped_closed_open
stopped_closed_fastened
32Example Payment authorization in class Order
2 parallel processes - authorization - order
handling
Authorizing
payment not ok
do check payment
payment ok
Rejected
Authorized
Delivered
33Concurrent state diagram for the class Order
Cancelled
Waiting
Waiting
Dispatching
Dispatching
Checking
Checking
Delivered
Authorizing
Authorizing
Authorized
Authorized
Rejected
34Rules of thumb
- Not every class needs a state diagram
- Often State diagram not very complex
- State diagrams are often used for UI and control
objects - Not too many concurrent sets of behavior
occurring in a single object (in that case split
into separate objects)
35Self Exercises
- Define a statechart diagram for
- an elevator
- a socker game
- an ATM
- a cellular
36Were Available!
- Questions?
- if you have any questions about contents of this
lecture or other course-related issues, please
come by during our office hours, or send us email - Dr. Joshua MWF, 12-1pm, ICT 548
- joshuar_at_cpsc.ucalgary.ca
- Dr. Walker WF, 1-2pm, ICT 546
- rwalker_at_cpsc.ucalgary.ca