You are on page 1of 18

System Analysis & Design

Statechart Diagram

Prepared by
Huda Amin Maghawry
Information Systems

Source
Mastering UML with Rational Rose 2002
Statechart Diagram
• It includes information about
• The various states in which an object can exist
• How the object transitions from one state to another
• How the object behaves differently in each of the
states

 For example, a bank account can exist in several


different states. It can be open, closed, or
overdrawn.

• A Statechart diagram shows the life cycle of a single


object, from the time that it is created until it is
destroyed.
Source
Mastering UML with Rational Rose 2002
.Statechart Diagram cont

• These diagrams are a good way to model the dynamic


behavior of a class

diagrams aren't created for every class. Only if


 Statechart
an object of the class can exist in several states, and
behaves very differently in each of the states

 Statechartdiagrams are created for documentation only,


no source code is generated from it

Source
Mastering UML with Rational Rose 2002
Statechart Diagram
. cont

 How to decide whether a class has significant dynamic


behavior:
 Look at its attributes - Consider how an instance of
the class might behave differently with different values
in an attribute (If you have an attribute called Status,
this can be a good indicator of various states)

 Examine the relationships of a class - Look for any


relationships with a zero in the multiplicity. Zeroes
indicate that the relationship is optional (Does an
instance of the class behave differently when the
relationship does or does not exist?)
Source
Mastering UML with Rational Rose 2002
Elements of Statechart Diagram
Notation Representation Element

It indicates what state the


object is in when it is first
Start State created. there is one and only
one start state (Mandatory)

It shows what state the object


is in just before it is destroyed.
Stop State you can have no stop state, or
there can be as many stop
states as you need

It is one of the possible NewState


State conditions in which an object
may exist

It is a movement from one


Transition state to another (can be
reflexive)
Source
Mastering UML with Rational Rose 2002
Actions
• While an object is in a particular state, there may be
some activity that it performs

• An activity is some behavior that an object carries out while it is in


a particular state (interruptible) – “do“

• An entry action is a behavior that occurs while the object is


transitioning into the state (noninterruptible) - "entry“

• An exit action occurs as part of the transition out of a state


(noninterruptible) - "exit“
Source
Mastering UML with Rational Rose 2002
.Actions cont

• The behavior in an activity, entry action, or exit action


can include sending an event to some other object

• For example, if the flight is delayed for more than four


hours, the flight object may need to send an event to a
flight scheduler object, which will automatically reschedule
the flight for another day

• Target is the object receiving the event


• Event is the message being sent
• Arguments are parameters of the message being sent
Source
Mastering UML with Rational Rose 2002
Transitions
• Event:

• An event is something that causes a transition from one


state to another to occur
• The transition arrow is labeled with the event name,
along with any arguments in parenthesis
• An automatic transition, which has no event, an object
automatically moves from one state to another as soon
as all the entry actions, activities, and exit actions have
occurred

Source
Mastering UML with Rational Rose 2002
Transitions
. cont

• Guard condition:

• A guard condition controls when a transition can or


cannot occur
• If a guard condition is present, it must be true in order
for the transition to occur
• The guard condition is listed along the transition arrow,
following any event, and is enclosed in square brackets

Source
Mastering UML with Rational Rose 2002
Transitions
. cont

• Action:

• An action is a noninterruptible behavior that occurs as


part of a transition
• Entry and exit actions are shown inside states, because
they define what happens every time an object enters or
leaves a state
• Transition actions will be drawn along the transition
line, because they won't apply every time an object
enters or leaves a state

Source
Mastering UML with Rational Rose 2002
Nested States
• To reduce number of arrows in diagram you can nest one
or more states inside another

• The nested states are referred to as substates, while the


larger state is referred to as a superstate

• If two or more states have an identical transition, they


can be grouped together into a superstate. Then, rather
than maintaining two identical transitions (one for each
state), the transition can be moved to the superstate

Source
Mastering UML with Rational Rose 2002
Nested States
. cont

Source
Without nested states
Mastering UML with Rational Rose 2002
Nested States
. cont

Superstate

Suberstate

Source
With nested states
Mastering UML with Rational Rose 2002
State History
• At times, you may need the system to remember which
state it was last in
• If you have three states in a superstate and then leave
the superstate, you may want the system to remember
where you left off inside the superstate

• In our example, if we want to temporarily suspend


reservations while the system is undergoing routine
maintenance, we may transition to a SuspendReservations
state while the maintenance is occurring
• Once the maintenance is done, we want to return to
whatever state the flight was in before the maintenance
started
Source
Mastering UML with Rational Rose 2002
State History: First Solution

The start stateSourcewill indicate where


the starting point
Mastering UML is in the
with Rational Rosesuperstate
2002
State History: Second Solution

We use state history to remember where the object was. If the


History option is set, an object can
leave a superstate and then return
Source and pick up right where it left off
Mastering UML with Rational Rose 2002
Assignment
• A flight begins in a Tentative state.
• Someone reviews the schedule to determine whether or not to
include the flight. If the schedule is rejected, the flight is deleted
and no further action can be taken.
• If the schedule is approved, the flight moves into a Scheduled
status. The flight schedule is posted to the Internet, and as soon as
it is 60 days or less before the flight, the flight becomes open.
• We can add and remove passengers from the flight, but as soon as
the last seat is sold, the flight is full. If someone then cancels their
reservation, the flight can become open again. Ten minutes before
takeoff, the flight is closed for reservations.
• If the plane has not yet arrived, the flight is delayed until either the
plane arrives or it has been four hours. After four hours, the flight is
canceled. If the plane has arrived, but there are fewer than 50
people, the flight is canceled.
• If the flight is canceled, the airline will find an alternate flight for
the passengers. If the plane does arrive, it takes off and lands,
which is the conclusion of this particular flight with recording of
Source
landing time. Mastering UML with Rational Rose 2002
Thanks For Listening

Source
Mastering UML with Rational Rose 2002

You might also like