You are on page 1of 19

ICS 222 OOAD

Class 32
Outline

State Diagram or State Chart or State Machine Diagram


State Chart Diagram for loanable and non-loanable books
Pictorial Representation of ATM State Diagram
State Chart Diagram
• Most of the UML diagrams show how objects interact to meet some system requirements.

• But there is lack of information on how the system decides what is the right thing to do.

• The choice of how to react (that is, which scenario is appropriate) depends on a state. Which is
indicated by the State diagram.

• Statechart diagram define different states of an object during its lifetime and these states are
changed by events.

• Statechart diagram describes the flow of control from one state to another state. Here, states are
defined as a condition in which an object exists and it changes when some event is triggered.

• The most important purpose of Statechart diagram is to model lifetime of an object from creation
to termination.
Following are the main purposes of using Statechart diagrams

 To model the dynamic aspect of a system.

 To model the life time of a Reactive system (External and Internal events).

 To describe different states of an object during its life time.


Essential Things to Draw State Chart Diagram

Initial state State – rounded rectangle to represent a state. A state


Final State represents the conditions or circumstances of an object of a
class at an instant of time.

Transition – Represents solid arrow, change of control


from one state to another.

Fork
Join

Composite state – a rounded rectangle to represent


internal activities using a composite state.
Self transition – Represents with solid arrow pointing
back to the state itself to represent a self-transition
Statechart Diagrams Basics
• States and Events

• Transitions

• Actions

• Decision Points Complex States

Composite States

Concurrent Substates

History States

Synch States
States and Events
• A state is a condition or situation in the life of an object during which it satisfies some
condition, performs some activity, or waits for some event.

• Objects (or Systems) can be viewed as moving from state to state.

• Viewing a system as a set of states and transitions between states is very useful for
describing complex behaviors, Understanding state transitions is part of system analysis
and design.

Simple States: Start and End States

• An event in the context of state machines is an occurrence of a provocation or


motivation that can trigger a state transition.

• Internal or External Events trigger some activity that changes the state of the system and
of some of its parts.

• Events pass information, which is explained by Objects actions.


Transition
• A transition is a relationship between two states
indicating that an object in the first state will perform
certain actions and enter the second state when a
specified event occurs and specified conditions are
satisfied.

• A Transition is the movement from one state to another


state

• Transitions between states occur as follows: 1. An


element is in a source state 2. An event occurs 3. An
action is performed 4. The element enters a target state

• Multiple transitions occur depend on application.

• A transition without an event and action is known as


automatic transitions.
Actions

• States can trigger actions.

• Five triggers for actions: • On Entry, Do, On Event, On Exit and Include

• An activity captures complex behaviour that may run for a long duration.
Complex States
•Composite States: can be further broken down into substates (either within
the state or in a separate diagram)
•Concurrent Substates (each substate is separated from the others by a
dashed line) are independent and can complete at different times
•History States allow the re-entering of a composite state at the point which it
was last left.
•Synch States is used in a concurrent state to indicate that the associated
concurrent transitions must meet up (or sync) before entering the next step.
Composite States

• Start the sub flow at the initial state of the composite state. Internal Concurrency
• Immediate and effective on any of the substances. External Synchronization.
Advice on Designing Classes with States Diagrams

•Keep the state diagram simple

•State diagrams can very quickly become extremely complex and confusing.

•At all time, you should follow the aesthetic rule: “Less is More”

•If the state diagram gets too complex consider splitting it into smaller classes.

•Check stability with the other view of the dynamics.

•Think about compound state changes in a collaboration or sequence


Building State chart Diagrams

• Identify entities that have complex behaviour.

• Determine the initial and final states of the entity.

• Identify the events that affect the entity.

• Working from the initial state, trace the impact of events and identify intermediate states.

• Identify any entry and exit actions on the states.

• Expand states using substates where necessary.

• If the entity is a class, check that the action in the state are supported by the operations and
relationships of the class, and if not extend the class.
A Simple Process for State Diagram

• Identify a class participating in behaviour whose Lifecyle is to be specified


• Model states
• Model events
• Model transitions
• Refine and elaborate as required
Online ordering system State Diagram
State Diagram for SSN Verification
State diagram showing a user interface navigation map for
Student actor

You might also like