Professional Documents
Culture Documents
Ooad Unit 5
Ooad Unit 5
3 Processes
and Threads, 5.4 Time and space, 5.5 State chart diagrams.
5.0 Advanced Behavioral Modeling:
5.1 Events and Signals
Introduction:
In state machines (sequence of states), we use events to model the occurrence of a stimulus that
can trigger an object to move from one state to another state. Events may include signals, calls,
and the passage of time or a change in state.
In UML, each thing that happens is modeled as an event. An event is the specification of a
significant occurrence that has a location in time and space. A signal, passing of time and change
in state are asynchronous events. Calls are generally synchronous events, representing invocation
of an operation.
UML allows us to represent events graphically as shown below. Signals may be represented as
stereotyped classes and other events are represented as messages associated with transitions
which cause an object to move from one state to another.
Types of Events:
Events may be external or internal. Events passed between the system and its actors are external
events. For example, in an ATM system, pushing a button or inserting a card are external events.
Internal events are those that are passed among objects living inside the system. For example, a
overflow exception generated by an object is an internal event.
In UML, we can model four kinds of events namely: signals, calls, passing of time and change in
state.
Signals:
A signal is a named object that is sent asynchronously by one object and then received by
another. Exceptions are the famous examples for signals. A signal may be sent as the action of a
state in a state machine or as a message in an interaction. The execution of an operation can also
send signals. In UML, we model the relationship between an operation and the events using a
dependency stereotyped with “send”, which indicates that an operation sends a particular signal.
Call Events:
A call event represents the dispatch of an operation from one object to another. A call event may
trigger a state change in a state machine. A call event, in general, is synchronous. This means
that the sender object must wait until it gets an acknowledgment from the receiver object which
receives the call event. For example, consider the states of a customer in an ATM application:
Modeling Exceptions:
To model exceptions,
1. For each class and interface and for each operation of such elements, consider the
exceptional conditions that might arise.
2. Arrange these exceptions in a hierarchy.
3. For each operation, specify the exceptions that it may rise.
5.2 State Machines
Introduction:
A state machine is a behavior that represents the sequences of states that an object undergoes
during its lifetime in response to events, together with its responses to those events.
The state of an object is a condition or situation during the life of an object during which it
satisfies some condition, performs some activity or waits for some event.
We can visualize a state machine in two ways: 1) by focusing on the control flow from one
activity to another (using activity diagrams) or 2) by focusing on the states of objects and the
transitions among those states (using state chart diagrams).
States:
A state is a condition or situation during the life of an object during which it satisfies some
condition, performs some activity, or waits for some event. An object remains in a state for a
finite amount of time. A state has several parts:
Name A textual string which distinguishes one state from other states
Entry/exit actions Actions executed on entering and exiting the state
Internal transitions Transitions that are handled without causing a change in state
Substates The nested structure of a state, involving disjoint or concurrent
substates
Deferred events A list of events that are not handled in that state, but are postponed or
queued for handling by the object in another state
A transition is visually represented as a solid directed line from the source state to the target
state. A self-transition is a transition whose source and target states are the same.
Event Trigger:
An event is a specification of a significant occurrence that has location in time and space. In state
machines, an event is an occurrence of stimulus that can trigger a state transition. For example,
the “play button” makes the music player to change from “idle” state to “playing”.
There can be triggerless transitions which are represented by a transition with no event trigger. A
triggerless transition also called a completion transition is triggered implicitly when its source
state has completed its activity.
Guard Condition:
A guard condition is rendered as a Boolean expression enclosed in square brackets and placed
after the trigger event. A guard condition is evaluated only after the trigger event for its transition
occurs. Therefore, it‟s possible to have multiple transitions from the same source state and with
the same event trigger, as long as those conditions don‟t overlap.
Action:
An action is an executable atomic computation. Actions may be method calls, signals or creation
of objects or destruction of objects.
Advanced States and Transitions:
UML‟s state machines provide a number of advanced features that help us to manage complex
behavioral models. Some of these advanced features include entry and exit actions, internal
transitions, activities and deferred events.
Entry and Exit Actions:
When the control enters a certain state, it might carry out a particular action. Such action is
known as an entry action. Similarly, a state might carry out a particular action when the control
leaves that state. Such action is known as exit action. Entry and exit actions are represented using
the keywords “entry” and “exit” respectively.
Internal Transitions:
In state machines, a state might process certain events without leaving the current state. Such
transitions which represent events that are handled without leaving the current state are known as
internal transitions. Internal transitions are different from self transitions in the sense that events
on self transitions are handled outside the current state.
Activities:
After entering the state, that state might do a set of actions. These actions are collectively known
as the activity performed by a state. In UML, activities are represented using the keyword “do”.
Deferred Events:
In some situations, a state might handle certain events in another state of the object. Such events
which are postponed to be handled later in another state are known as deferred events. In UML,
deferred events are represented with the “do” action.
Substates
A substate is a state included in another state. In UML, we render a composite state just like a
normal state, but with an optional graphic compartment that shows a nested state machine.
Substates may be nested to any level.
Sequential Substates:
Consider the state machine for ATM system:
Substates such as Validating and Processing are called sequential or disjoint substates. Given a
set of disjoint states in an enclosing composite state, the object is said to be in the composite
state and in only one of the disjoint substates at a time. Therefore, sequential substates divide the
state space of the composite state into disjoint states. A nested sequential state machine may have
at most one initial state and one final state.
History States:
Unless otherwise specified, when a transition enters a composite state, the action of the nested
state machine starts over again at its initial state. However, there are situations in which we
might want the state machine to remember the last substate that was active prior to leaving the
composite state.
For example, in modeling the behavior of an agent which performs unattended backup of
computers across the network, we like it to remember where it was in the process if it ever gets
interrupted by, for example, a query from the operator.
A history state allows a composite state that contains sequential substates to remember the last
substate that was active in it prior to the transition from the composite state. In UML, a history is
represented as a hollow circle with the symbol „H‟ as shown in the below figure:
Concurrent Substates:
Concurrent substates allow us to specify two or more state machines that execute in parallel in
the context of the enclosing object.
For example, in the below figure, the Maintenance mode is decomposed into two concurrent
substates, Testing and Commanding, shown by nesting them in the Maintenance state but
separating them from one another with a dashed line. Each of these concurrent substates is
further divided into sequential substates.
Execution of these two concurrent substates continues in parallel. Eventually, each nested state
machine reaches its final state. If one concurrent substate reaches its final state before the other,
control in that substate waits at its final state. When both the nested state machines reach their
final state, control from the two concurrent substates joins back into one flow.