CPSC333 SENG311: Foundations Principles of SE - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

CPSC333 SENG311: Foundations Principles of SE

Description:

... state may occur (directly) within a composite state. End state represents completion of a composite ... order handling. CPSC333 / SENG 311 - State Diagrams. 33 ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 37
Provided by: rosejoshua
Category:

less

Transcript and Presenter's Notes

Title: CPSC333 SENG311: Foundations Principles of SE


1
CPSC333 / SENG311 Foundations / Principles of SE
  • Events and State Diagrams

2
Agenda
  • Current position in development process
  • Events
  • State diagrams

3
Main 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
4
Refined 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
5
State 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)

6
Object 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
7
Events, 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

8
Call events
  • Call event dispatch of operation
  • Call event is synchronous

9
Time 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()

10
Change and Time Events - Example
/ turn around
11
Signals
  • Modeled as stereotyped classes
  • Can have attributes

ltltsendgtgt
12
Signal support inheritance
13
Exceptions
  • In UML kinds of signals to denote an erroneous
    condition
  • can be raised by operations

ltltsendgtgt
ltltsendgtgt
ltltsendgtgt
14
Self-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.

15
State 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
16
State changes (2)
  • Events Messages or signals received
  • Events may or may not change the state
  • Self-transition

deposit
overdrafted
withdraw
withdraw
deposit
ok
17
State 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
18
State 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!

19
State 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

20
Example of Statechart Diagrams Order Management
21
State 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
22
Problem 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

23
Transitions 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
24
State diagram notation (4)
Superstate
Event A
State-A
State-B
State-A
State-B
Event C
Event B
Composite state Sequential substates
25
Superstate / 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
26
State 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
27
Example of Statechart DiagramsStates of a
hockey game
28
Hockey example with superstate
Normal
time is up tie
shootout
playing
Fighting
penalty
face off
time is uo win
end of game
break
29
Some 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...

30
Some 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

31
Orthogonal 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
32
Example Payment authorization in class Order
2 parallel processes - authorization - order
handling
Authorizing
payment not ok
do check payment
payment ok
Rejected
Authorized
Delivered
33
Concurrent state diagram for the class Order
Cancelled
Waiting
Waiting
Dispatching
Dispatching
Checking
Checking
Delivered
Authorizing
Authorizing
Authorized
Authorized
Rejected
34
Rules 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)

35
Self Exercises
  • Define a statechart diagram for
  • an elevator
  • a socker game
  • an ATM
  • a cellular

36
Were 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
Write a Comment
User Comments (0)
About PowerShow.com