Title: Lecture 13: Statechart Diagrams Activity Diagrams
1Lecture 13Statechart DiagramsActivity Diagrams
MIS 160 Systems Development Life Cycle I
2Object Behavior
- Help to further describes functional requirements
- Description of the actions an object performs
- Defines object responses to messages --object
behavior
3Statechart Diagrams
- Shows all possible states for an object and the
events that cause the object to change states - Create a SD for every object that has clearly
identifiable states - Shows the (interesting) behavior of a single
object across many use cases
4Components of Statechart Diagrams
- Always have
- States
- Events
- Transitions
- Actions
- Activities
- May also have
- Guards
- Synchronization bars
- Decision psuedostates
5Statechart Diagram Symbols
A STATE AN INITIAL STATE A FINAL
STATE AN EVENT A TRANSITION
anEvent
6States
- A condition during the life of an object
- A form or mode of being
- Satisfies a criteria
- Performs an action
- Waits for an event
- Defined by the set of values currently held by
its attributes and by its established behaviors - Transition
- Mechanism that causes an object to leave one
state and change to a new state
7Event
- Something being done to the object
- Causes an object to change states
- Only 1 event can move an object from state 1 to
state 2
8A VERY Simple Example A Printer
States
OnButtonPushed
Off
On
Transition
Event
9Actions
- Something that the object does
- Occurs in direct response (reaction) to an event
before moving to a state - Action-expression
- Procedural statement describing action performed
- Executes when the transition fires
10Another VERY Simple Example A Printer
Working
Load sheet Print sheet Eject sheet
OnButtonPushed
Idle
Actions
11Activities
- Associated with states
- Entry - things that happen on entry
- Exit - things that happen on exit
- Do - things that happen while in the state
12and Yet Another VERY Simple Example A Printer
Working
entry/Load sheet Do/Print sheet Exit/Eject sheet
OnButtonPushed
Idle
13Guards
- Guard condition
- A logical condition that returns only true or
false - Can be used for events, actions, and activities
14A VERY Simple Example A Printer
Guard
Working
OnButtonPushed Safety cover closed/statusself-
test()
Load sheet Print sheet Eject sheet
Idle
15Decision Psuedostate
- A decision point in the path of a statechart
diagram
Working
OnButtonPushed
Load sheet Print sheet Eject sheet
Paper tray filled
Idle
Paper tray not filled
Error
16Building Statechart Diagrams
- Set the context
- Identify behaviors from your class diagram
- look at interaction diagrams and list all
relevant input and output messages - Identify the initial final, and stable states of
the object - Determine the order in which the object will pass
through stable states - Identify the events, actions, and guard
conditions associated with the transitions
17Superstate and Substate
- States can be nested within states
- Superstates
- The larger (parent) state
- Substates
- Nested within the superstate
- A transition is indicated to a superstate, then
the default substate is entered
18Example of Superstate/Substate
19Concurrent Behavior
- Objects can do multiple things in parallel
- Statechart diagrams represent concurrent behavior
with multiple paths called threads - Vertical bars indicate where concurrent behavior
begins or ends
20Concurrent Substates
21Concurrent States with Synchronization Bar
22Concurrent Substate
Taking MIS 160
Proposal Accepted
Project Completed
Proposal
Project
Homework
Homework Completed
23Composite States
- A state can be decomposed
- into sequential substate
- using and-relationships into the concurrent
substates - using or-relationships into mutually exclusive
disjoint substates
24OR / AND Transitions with Synchronization Bar
25Example of Sequential Substate
- e.g. research proposal and research project
26Example of Disjoint Substate
- e.g. comprehensive exam or masters thesis /
project
27Pros and Cons of State Diagrams
- Pros
- Gives a good sense of what events should occur
and what effects they may have on the objects. - Gives a good overview of relationships within a
system
- Cons
- Can get too complicated
- Difficult to visualize the behavior of the whole
system
28Activity Diagrams
29Activity Diagrams
- Resolves the limitation of state diagrams
- State diagram is limited limits to one object and
only shows the behavior of the object - Activity diagram shows behavior of multiple
objects and use cases - Show general sequence of actions for several
objects and use cases
30Activity Diagrams
- Activity diagrams can be used to
- model workflow
- focus on activities as viewed by actors
- often follow use case descriptions (but can be
broader) - model methods
- similar to flowcharts
31Activity Diagram
- Uses in connection with workflow
- Uses in describing the behavior that has a lot of
parallel process - Focus on flows driven by internal processing
- Each activity in the diagram is a method on a
class
32Notation
- Synchronization bar
- Branch or Merge (Decision)
33Constructing Activity Diagrams
- For workflow
- determine actors
- draw in order of occurrence
- can use branches
- For methods
- determine objects
- look for computations, logic, etc.
- can use branches
34Example of Activity Diagram
35Organize Actions
- Actions may be organized into swimlanes.
- Swimlanes are a kind of package for organizing
responsibility for activity within a class - Arrange activity diagrams into vertical zones
separated by lines
36Example of Swimlanes
37Action-Object Flow Relationships
- Object flow
- is shown by dashed arrows, which shows an input
to or output by an action - Control flow
- is shown by solid arrows, when an action produces
an output which is an input, by a subsequent
action. This signifies a control constraint.
38Example-actions and object flow
39State or Activity Diagram?
- If you want to look at the behavior of a single
object across many use cases, use state diagram. - If you want to look at behavior of multiply
objects across many use cases or many threads,
consider activity diagram.