Unit - II Notes-1
Unit - II Notes-1
Links
When an object passes a message to another object, the receiving object might
in turn send a message to another object, which might send a message to yet a
different object and so on.
In UML, the first kind of representation is called a sequence diagram and the second
kind of representation is called a collaboration diagram. Both sequence and
collaboration diagrams are known as interaction diagrams.
Interaction Diagrams
Sequence diagrams have two features that distinguish them from collaboration
diagrams.
First, there is the object lifeline. An object lifeline is the vertical dashed line that
represents the existence of an object over a period of time. Most objects that
appear in an interaction diagram will be in existence for the duration of the
interaction, so these objects are all aligned at the top of the diagram, with their
lifelines drawn from the top of the diagram to the bottom.
Second, there is the focus of control. The focus of control is a tall, thin rectangle that
shows the period of time during which an object is performing an action, either
directly or through a subordinate procedure. The top of the rectangle is aligned with
the start of the action; the bottom is aligned with its completion (and can be marked
by a return message).
Collaboration Diagrams
Second, there is the sequence number. To indicate the time order of a message, you
prefix the message with a number (starting with the message numbered 1), increasing
monotonically for each new message in the flow of control (2, 3, and so on). To show
nesting, you use Dewey decimal numbering (1 is the first message; 1.1 is the first
message nested in message 1; 1.2 the second message nested in message 1; and so on).
Use Cases
Use cases provide a way for your developers to come to a common understanding
with your system's end users and domain experts.
For example, you can specify how an ATM system should behave by stating in use
cases how users interact with the system; you don't need to know anything about the
inside of the ATM at all. Use cases specify desired behavior, they do not dictate how
that behavior will be carried out.
Use Cases and Actors
Typically, an actor represents a role that a human, a hardware device, or even
another system plays with a system. For example, if you work for a bank, you might
be a LoanOfficer. If you do your personal banking there, as well, you'll also play the
role of Customer. An instance of an actor, therefore, represents an individual
interacting with the system in a specific way.
You can define general kinds of actors (such as Customer) and specialize them (such
as CommercialCustomer) using generalization relationships.
Actors may be connected to use cases only by association. An association between
an actor and a use case indicates that the actor and the use case communicate
with one another, each one possibly sending and receiving messages.
Use case diagrams are one of the five diagrams in the UML for modeling the
dynamic aspects of systems (activity diagrams, statechart diagrams, sequence
diagrams, and collaboration diagrams are four other kinds of diagrams in the UML
for modeling the dynamic aspects of systems).
Each one shows a set of use cases and actors and their relationships.
Activity diagrams are one of the five diagrams in the UML for modeling the
dynamic aspects of systems. An activity diagram is essentially a flowchart,
showing flow of control from activity to activity.
Interaction diagrams emphasize the flow of control from object to object, activity
diagrams emphasize the flow of control from activity to activity.
There's no notational distinction between action and activity states, except that
an activity state may have additional parts, such as entry and exit actions (actions
which are involved on entering and leaving the state, respectively) and
submachine specifications.
When the action or activity of a state completes, flow of control passes immediately
to the next action or activity state. You specify this flow by using transitions to show
the path from one action or activity state to the next action or activity state. In the
UML, you represent a transition as a simple directed line
Indeed, a flow of control has to start and end someplace (unless, of course, it's an
infinite flow, in which case it will have a beginning but no end). Therefore, as the
figure shows, you may specify this initial state (a solid ball) and stop state (a solid
ball inside a circle).
Advanced Behavioral Modeling
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.
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.
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:
Time and Change Events
A time event represents the passage of time. In UML, we model the time event
using the “after” keyword followed by an expression that evaluates a period of
time.
Using an interaction, you can model the behavior of a society of objects that
work together. Using a state machine, you can model the behavior of an
individual object. A state machine is a behavior that specifies the sequences
of states an object goes through during its lifetime in response to events,
together with its responses to those events.
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. For example, a Heater in a
home might be in any of four states: Idle (waiting for a command to start heating
the house), Activating (its gas is on, but it's waiting to come up to temperature),
Active (its gas and blower are both on), and ShuttingDown (its gas is off but
its blower is on, flushing residual heat from the system).
A state has several parts.
1. Name A textual string that distinguishes the state from other states; a state
may be anonymous, meaning that it has no name
2. Entry/exit actions
Actions executed on entering and exiting the state, respectively
3. Internal transitions
Transitions that are handled without causing a change in state
2. Event trigger
The event whose reception by the object in the source state makes the transition
eligible to fire, providing its guard condition is satisfied
3. Guard condition
A Boolean expression that is evaluated when the transition is triggered by the reception of the
event trigger; if the expression evaluates True, the transition is eligible to fire; if the
expression evaluates False, the transition does not fire and if there is no other transition that
could be triggered by that same event, the event is Lost
4. Action
An executable atomic computation that may directly act on the object that owns the
state machine, and indirectly on other objects that are visible to the object
5. Target state
The state that is active after the completion of the transition
Processes and Threads
A process is a heavyweight flow that can execute concurrently with other processes.
A thread is a lightweight flow that can execute concurrently with other threads
within the same process.
An active object is an object that owns a process or thread and can initiate control
activity.
An active class is a class whose instances are active objects.
Graphically, an active class is rendered as a rectangle with thick lines. Processes and
threads are rendered as stereotyped active classes
Flow of Control
In a sequential system, there is a single flow of control. i.e, one thing, and one thing only,
can take place at a time.
In a concurrent system, there is multiple simultaneous flow of control i.e, more than one
thing can take place at a time.
Statechart diagram is one of the five UML diagrams used to model the dynamic
nature of a system. They define different states of an object during its lifetime and
these states are changed by events. Statechart diagrams are useful to model the
reactive systems. Reactive systems can be defined as a system that responds to
external or internal events.
Statechart diagram describes the flow of control from one state to another state.
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 is an example of a Statechart diagram where the state of Order
object is analyzed
The first state is an idle state from where the process starts. The next states are
arrived for events like send request, confirm request, and dispatch order. These
events are responsible for the state changes of order object.
During the life cycle of an object (here order object) it goes through the
following states and there may be some abnormal exits. This abnormal exit
may occur due to some problem in the system. When the entire life cycle is
complete, it is considered as a complete transaction as shown in the following
figure. The initial and final state of an object is also shown in the following
figure.