Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 29

Software Construction

Lecture 11
State Chart & Activity Diagrams

1
StateChart Diagram
 Use Cases describe the requirements of the system

 Class Diagrams describe the static structure of the system

 Interaction diagrams describe how objects interact to satisfy the


requirements

 State Diagrams can describe the behaviour of an object when it


receives a message
StateChart Diagram
Events, States and Transitions
 Event
— An event is something done to the object that triggers state transitions

— Usually an event corresponds to the receipt of a message

 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.

— The response may involve either:


o Moving into another state or

o Remaining in the same state


StateChart Diagram
 A statechart Diagram may be applied to
 Software classes
 Conceptual classes
 Use cases

 Statechart diagrams are used to better understand or


communicate dynamic behavior of classes / use cases in
response to events
StateChart Diagram
 Use case Statechart diagram
 Depicts the overall system events and their sequence within a use case

 Shows legal sequence of events


 During the processDocument use case in a word processor, it is not
legal to perform the File-Save operation until the File-New or File-
Open event has happened.
 During the process Sale use case in the NextGen POS
application, it is illegal to perform the makePayment operation
until the endSale event has happened
StateChart Diagram

Process Sale

makeNewSale
WaitingForSale EnteringItems

(external system
events) enterItem
endSale

makePayment
WaitingForPayment

Use Case StateChart Diagram for Process Sale


StateChart Diagram
 Utility of use case statechart Diagrams
 Legal order of events in a use case
 Why order?
 During design, it is necessary to create and implement a design
that ensures no out of sequence events, to achieve desired
functionality; otherwise error condition is possible
 e.g. Payment without a Sale
 In a domain with many system events, conciseness and thoroughness
of use case statechart diagram helps a designer to ensure that nothing
is missed
StateChart Diagram
Process Sale

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

 Prefer using statechart diagrams to illustrate external


and temporal events and the reaction to them
StateChart Diagram
 Other Notations
 UML notation for Statechart contain a rich set of features:
Three significant features are
 Transition actions
 Transition guard condition
 Nested states
StateChart Diagram
 Transition Actions and Guards
 A transition can cause an action to fire
 In software, it is invocation of some method of a class
 This transition may have a conditional guard (or Boolean test)
-- The transition only occurs if condition is passed
 Example …
StateChart Diagram
transition action

off hook / play dial tone


[valid subscriber]
Idle Active

on hook

guard condition

Transition action and guard notation


StateChart Diagram
 Nested States
 A state allows nesting to contain substates;
 A substate inherits the transition of its superstate
 Substates may be graphically shown by nesting them in a
superstate box
 Example …
StateChart Diagram

Active
[valid subscriber]
Idle

PlayingDialTone Talking

digit digit connected

Nested States Dialing


complete
Connecting
Activity Diagrams
Activity Diagrams
 UML activity diagram shows sequential
and parallel activities in a process.

 Useful for modeling business processes,


workflows, data flows, and complex
algorithms.
Basic Activity Diagram
More UML Activity Diagram Notation
Process Sale Activity Diagrams
Questions

You might also like