Unit– 3 State Modeling
● Events
Events are some occurrences that can trigger state transition of an object or a group of objects. Events
have a location in time and space but do not have a time period associated with it. Events are generally
associated with some actions.
Examples of events are mouse click, key press, an interrupt, stack overflow, etc.
Events that trigger transitions are written alongside the arc of transition in state diagrams.
Example
Considering the example shown in the above figure, the transition from Waiting state to Riding state
takes place when the person gets a taxi. Likewise, the final state is reached, when he reaches the
destination. These two occurrences can be termed as events Get_Taxi and Reach_Destination. The
following figure shows the events in a state machine.
● External and Internal Events
External events are those events that pass from a user of the system to the objects within the system. For
example, mouse click or key−press by the user are external events.
Internal events are those that pass from one object to another object within a system. For example, stack
overflow, a divide error, etc.
● Deferred Events
Deferred events are those which are not immediately handled by the object in the current state but are
lined up in a queue so that they can be handled by the object in some other state at a later time.
● Event Classes
Event class indicates a group of events with common structure and behavior. As with classes of objects,
event classes may also be organized in a hierarchical structure. Event classes may have attributes
associated with them, time being an implicit attribute. For example, we can consider the events of
departure of a flight of an airline, which we can group into the following class −
Flight_Departs (Flight_No, From_City, To_City, Route)
● States
The state is an abstraction given by the values of the attributes that the object has at a particular time
period. It is a situation occurring for a finite time period in the lifetime of an object, in which it fulfils
certain conditions, performs certain activities, or waits for certain events to occur. In state transition
diagrams, a state is represented by rounded rectangles.
● Parts of a state
Name − A string differentiates one state from another. A state may not have any name.
Entry/Exit Actions − It denotes the activities performed on entering and on exiting the state.
Internal Transitions − The changes within a state that do not cause a change in the state.
Sub–states − States within states.
● Initial and Final States
The default starting state of an object is called its initial state. The final state indicates the completion of
execution of the state machine. The initial and the final states are pseudo-states, and may not have the
parts of a regular state except name. In state transition diagrams, the initial state is represented by a filled
black circle. The final state is represented by a filled black circle encircled within another unfilled black
circle.
● Transitions and Conditions
A transition denotes a change in the state of an object. If an object is in a certain state when an event
occurs, the object may perform certain activities subject to specified conditions and change the state. In
this case, a state−transition is said to have occurred. The transition gives the relationship between the first
state and the new state. A transition is graphically represented by a solid directed arc from the source
state to the destination state.
The five parts of a transition are −
Source State − The state affected by the transition.
Event Trigger − The occurrence due to which an object in the source state undergoes a transition
if the guard condition is satisfied.
Guard Condition − A Boolean expression which if True, causes a transition on receiving the event
trigger.
Action − An un-interruptible and atomic computation that occurs on the source object due to
some event.
Target State − The destination state after completion of transition.
Example
Suppose a person is taking a taxi from place X to place Y. The states of the person may be: Waiting
(waiting for taxi), Riding (he has got a taxi and is travelling in it), and Reached (he has reached the
destination). The following figure depicts the state transition.
● State Diagrams
A state diagram is used to represent the condition of the system or part of the system at finite instances of
time. It’s a
behavioral diagram and it represents the behavior using finite state transitions.
● State Machine diagrams are also referred to as State Machines Diagrams and State-Chart
Diagrams.
● These terms are often used interchangeably. So simply, a state machine diagram is used to
model the dynamic behavior of a class in response to time and changing external stimuli.
● We can say that each and every class has a state but we don’t model every class using State
Machine diagrams.
● We prefer to model the states with three or more states.
Let’s understand State Machine Diagram with the help of an example:
Example:
● Basic components and notations of a State Machine diagram
● Initial state
We use a black filled circle represent the initial state of a System or a Class.
● Transition
We use a solid arrow to represent the transition or change of control from one state to another. The arrow
is labelled with the event which causes the change in state.
● State
We use a rounded rectangle to represent a state. A state represents the conditions or circumstances
of an object of a class at an instant of time.
● Fork
We use a rounded solid rectangular bar to represent a Fork notation with incoming arrow from the parent
state and outgoing arrows towards the newly created states. We use the fork notation to represent a state
splitting into two or more concurrent states.
● Join
We use a rounded solid rectangular bar to represent a Join notation with incoming arrows from the
joining states and outgoing arrow towards the common goal state. We use the join notation when two or
more states concurrently converge into one on the occurrence of an event or events.
● Self transition
We use a solid arrow pointing back to the state itself to represent a self transition. There might be
scenarios when the state of the object does not change upon the occurrence of an event. We use self
transitions to represent such cases.
● Composite state
We use a rounded rectangle to represent a composite state also. We represent a state with internal
activities using a composite state.
● Final State
We use a filled circle within a circle notation to represent the final state in a state machine diagram.
● State Diagram behavior Advanced State Modeling Nested state diagram
● State Diagram behavior Advanced State Modeling
A state machine diagram models the behavior of a single object, specifying the sequence of
events that an object goes through during its lifetime in response to events. As an example, the
following state machine diagram shows the states that a door goes through during its lifetime.
● Nested state diagram
A nested state diagram is used to model the complex system as the regular state diagram is inadequate in
describing the large and complex problem. The nested state diagram is the concept of advanced state
modeling.
Conventionally a complex system has much redundancy. This redundancy can be resolved by
restructuring the complex system. One method to restructure a complex system is to expand the state that
has certain sub states.
● Nested states
A state can contain other states, often called nested states or substates. If you are modeling
complex state machines, use nested states to separate detailed behavior into multiple levels. States
can also contain actions that identify the tasks that can occur when an object is in a particular
state.
● Signal Generalization
● signals into generalization hierarchy with inheritance of signal attributes
● View every actual signal as a leaf on a generalization tree of signals.
● Received signal triggers transitions that are defined for any ancestor signal type. – E.g., typing an
‘a’ would trigger a transition on signal Alphanumeric as well as signal KeyboardCharacter.
● A signal hierarchy permits different levels of abstraction to be used in a model. – E.g., some state
might handle all i/p characters the same; other states might treat control characters differently
from printing characters .
● Concurrency
Concurrency allows more than one object to receive events at the same time and more than one
activity to be executed simultaneously. Concurrency is identified and represented in the dynamic
model. To enable concurrency, each concurrent element is assigned a separate thread of control.
● State Model
States are unique and meaningful configurations of the system. In some cases, a state may be defined by
a particular combination of values assigned to certain variables. In others, several sets of possible values
are grouped together within a single state. Transitions denote changes from one state to another.
Transitions are triggered by events and can have effects that produce some visible behavior.
state model for a streaming media player
UML state models are one way to visualize the behavior of a system from the perspective of its states and
transitions. an example of a state model for a streaming media player. The player has four states:
Connecting, Buffering, Playing, and Closing. The arrows between states denote transitions, with the
following events defined: Connected, Ready, Suspended, Canceled, and Finished.
● Relation of class and State Models Interaction Modeling Use case models
A class diagram is a graph whose nodes are classes and whose arcs are relationships among classes. The
state model describes the aspects of an object that change over time. The state diagram is a graph whose
nodes are states and whose arcs are transitions between states caused by events.
A relationship is a general term covering the specific types of logical connections found on class and
object diagrams
Interaction Modeling The interaction model describes how objects interact to produce useful results.
Interactions can be modeled at different levels of abstraction. At higher level use cases describe how a
s/m interacts with outside actors. The next level, sequence diagrams are used. Finally, activity diagrams
are used.
Use case :Use case in software engineering and systems engineering is a description of a system’s
behavior as it responds to a request that originates from outside of that system. In other words, a use case
describes "who" can do "what" with the system in question. The use case technique is used to capture a
system's behavioral requirements by detailing scenario-driven threads through the functional
requirements.
A use case defines the interactions between external actors and the system under consideration to
accomplish a goal. An actor specifies a role played by a person or thing when interacting with the
[Link] same person using the system may be represented as different actors because they are playing
different roles. For example, "Joe" could be playing the role of a Customer when using an Automated
Teller Machine to withdraw cash, or playing the role of a Bank Teller when using the system to restock
the cash drawer.
A business use case is described in technology-free terminology which treats system as a black box and
describes the business process that is used by its business actors (people or systems external to the
business) to achieve their goals (e.g., manual payment processing, expense report approval, manage
corporate real estate)
A system use case is normally described at the system functionality level (for example, create voucher)
and specifies the function or the service that the system provides for the user. The system use case will
describe what the actor achieves interacting with the system. For this reason it is recommended that
system use case specification begin with a verb (e.g., create voucher, select payments, exclude payment,
cancel voucher).
A use case should:
Describe what the system shall do for the actor to achieve a particular goal. Include no
implementation-specific language. Be at the appropriate level of detail. Not include detail regarding user
interfaces and screens. This is done in user-interface design.
● Sequence Models
UML guides the creation of multiple types of diagrams such as interaction, structure, and behavior
diagrams. A sequence diagram is the most commonly used interaction diagram.
● Interaction diagram
An interaction diagram is used to show the interactive behavior of a system. Since visualizing the
interactions in a system can be difficult, we use different types of interaction diagrams to capture various
features and aspects of interaction in a system.
● A sequence diagram simply depicts the interaction between the objects in a sequential order
i.e. the order in which these interactions occur.
● We can also use the terms event diagrams or event scenarios to refer to a sequence diagram.
● Sequence diagrams describe how and in what order the objects in a system function.
● These diagrams are widely used by businessmen and software developers to document and
understand requirements for new and existing systems.
● Activity Models Advanced interaction Modeling Use case relations
An activity diagram shows the sequence of steps that make up a complex process, such as an
algorithm or workflow.
Activity diagrams are most useful during the early stages of designing algorithms and workflows.
Activity diagram is like a traditional flowchart in that it shows the flow of control from step to
step
Activity diagram Notation
● Start at the top black circle
● If condition 1 is TRUE, go right; if condition 2 is TRUE, go down
● At first bar (a synchronization bar), break apart to follow 2 parallel paths
● At second bar, come together to proceed only when both parallel activities are done
Activity – an oval Trigger – path exiting an activity Guard – each trigger has a guard, a
logical expression that evaluates to ―true‖ or ―false‖
● Synchronization Bar – can break a trigger into multiple triggers operating in parallel or
can join multiple triggers into one when all are complete
● Decision Diamond – used to describe nested decisions (the first decision is indicated by
an activity with multiple triggers coming out of it)
● Procedural sequence Models
Sequence Diagrams with Passive Objects A passive object is not activated until it has been
called.
● Special constructs of activity Models
● Sending and receiving signals
● Swim lanes
● Object flows
● Swim lanes
● Swimlanes - Activity Diagrams that show activities by class
● Arrange activity diagrams into vertical zones separated by lines
● Each zone represents the responsibilities of a particular class (in this example, a particular
department)
● Object flows