Uml Unit-3
Uml Unit-3
Uml Unit-3
IV B.Tech - I Semester
UNIFIED MODELLING LANGUAGE(UNIT-4)
V.TATARAO
Asst.Professor
CSE DEPT
UNIFIED MODELLING LANGUAGE UNIT-4
UNIT-IV
Syllabus:UNIT-IV
UNIT-IV: Basic Behavioral Modeling: Interactions, Interaction diagrams, Use cases, Use case Dia-
grams, Activity Diagrams.
Behavioral Modeling
Interactions
Introduction:
In UML, the dynamic aspects of a system can bemodeledusing interactions. Interactions contain
messages that are exchangedbetweenobjects. A message can be an invocation of an operation or a
signal. The messages mayalsoincludecreation and destruction of otherobjects.
We can use interactions to model the flow of control within an operation, a class, a component, a
use case or the system as a whole. Using interaction diagrams, we can model these flows in two
ways: one is by focusing on how the messages are dispatched across time and the second is by
focusing on the structural relationships between objects and then consider how the messages are
passed between the objects. Graphically a message is rendered as a directed line with the name of
its operation as show below:
Interaction (Definition):
An interaction is a behaviorthatcontains a set of messages exchangedamong a set of objectswithin a
context to accomplish a purpose. A message isspecification of a communication
betweenobjectsthatconveys information with the expectation that the activitywillsucceed.
Objects and Roles:
The objectsthatparticipate in an interaction are eitherconcretethings or prototypicalthings. As a
concretething, an objectrepresentssomething in the real world. For example, p an instance of the
class Person, mightdenote a particularhuman. Alternately, as a prototypicalthing, p
mightrepresentany instance of Person.
Links:
A link is a semantic connection among objects. In general, a link is an instance of association.
Wherever, a class has an association with another class, there may be a link between the instances
of the two classes. Wherever there is a link between two objects, one object can send messages to
another object. We can adorn the appropriate end of the link with any of the following standard
stereotypes:
To model the sequence of a message, we can explicitlyrepresent the order of the message relative to
the start of the sequence by prefixing the message with a sequencenumber set apart by a colon
separator.
Most commonly, we can specify a procedural or nested flow of control, rendering using a filled
solid arrowhead. Less common but also possible, you can specify a flat flow of control, rendered
using a stick arrowhead. We will use flat sequences only when modeling interactions in the context
of use cases that involve the system as a whole, together with actors outside the system. In all other
cases, we will use procedural sequences, because they represent ordinary, nested operation calls of
the type we find in most programming languages.
Representation:
Whenwe model an interaction, wetypicallyincludebothobjects and messages. We can
visualizethoseobjects and messages involved in an interaction in twoways: by emphasizing the time
ordering of messages and by emphasizing the structural organization of the objectsthatsend and
receive messages. In UML, the first kind of representationiscalled a sequencediagram and the
second kind of representationiscalled a collaboration diagram. Bothsequence and collaboration
diagrams are known as interaction diagrams.
Sequence diagrams and collaboration diagrams are isomorphic, meaning that we can take one and
transform it into the other without loss of information. Sequence diagram lets us to model the
lifeline of an object. An object’s lifeline represents the existence of the object at a particular time. A
collaboration diagram lets us to model the structural links that may exist among the objects in the
interaction.
Consider the following example of railway reservation system’s sequence and collaboration
diagrams:
Interaction Diagrams
Introduction:
An interaction diagramrepresents an interaction, whichcontains a set of objects and the
relationshipsbetweenthemincluding the messages exchangedbetween the objects. A
sequencediagramis an interaction diagram in which the focus is on time ordering of messages.
Collaboration diagramisanother interaction diagram in which the focus is on the structural
UNIFIED MODELLING LANGUAGE UNIT-4
organization of the objects. Bothsequencediagrams and collaboration diagrams are
isomorphicdiagrams.
Common Properties:
Interaction diagramsshare the propertieswhich are common to all the diagrams in UML. They are: a
namewhich identifies the diagram and the graphical contents which are a projection into the model.
Contents:
Interaction diagramscommonlycontain:
1. Objects
2. Links
3. Messages
Like all otherdiagrams, interaction diagramsmaycontain notes and constraints.
SequenceDiagrams:
A sequencediagramis one of the two interaction diagrams. The sequencediagramemphasizes on the
time ordering of messages. In a sequencediagram, the objectsthatparticipate in the interaction are
arranged at the top along the x-axis. Generally, the objectwhichinitiates the interaction isplaced on
the left and the next important object to its right and so on. The messages dispatched by the objects
are arrangedfrom top to bottomalong the y-axis. This gives the user the detail about the flow of
control over time.
Sequencediagram has twofeaturesthatdistinguishthemfrom collaboration diagrams. First, thereis the
objectlifeline, whichis a vertical dashed line thatrepresents the existence of an object over a period
of time. Most of the objects are alive throughout the interaction. Objectsmayalsobecreatedduring
the interaction with the receipt of the message stereotypedwithcreate.
Objectsmayalsobedestroyedduring the interaction with the receipt of the message stereotypedwith
destroy.
Second, thereis focus of control whichisrepresented as a thin rectangle over the life line of the
object. The focus of control represents the points in time at which the objectisperforming an action.
We can alsorepresentrecursion by using a self message.
Collaboration Diagrams:
A collaboration diagramis one of the two interaction diagrams. The collaboration
diagramemphasizes on the structural organization of the objects in the interaction. A collaboration
diagramis made up of objectswhich are the vertices and these are connected by links. Finally, the
messages are represented over the links between the objects. This gives the user the detail about the
flow of control in the context of structural organization of objectsthatcollaborate.
Collaboration diagram has two features that distinguish them from the sequence diagrams. First,
there is a path which indicates one object is linked to another. Second, there is a sequence number
to indicate the time ordering of a message by prefixing the message with a number. We can use
Dewey decimal numbering system for the sequence numbers. For example a message can be
numbered as 1 and the next messages in the nested sequence can be numbered 1.1 and so on.
Common Uses:
We use interaction diagrams to model the dynamic aspects (interactions) of the system. Whenwe
use an interaction diagram to model somedynamic aspect of a system, we do so in the context of the
system as a whole, a subsystem, an operation or a class. Wetypically use the interaction diagrams in
twoways:
1. To model flows of control by time ordering
2. To model flows of control by organization
Use Cases
Introduction:
Use case modeling describeswhat a system does or whatis the functionalityprovided by the system
to benefit the users. Use case modeling wascreated by Ivar Jacobson. More thananyotherdiagrams
in UML, use case diagramsallow us to quicklygather the requirements of the software system. The
primary components of a use case model are use cases, actors or roles and the system
beingmodeledalsoknown as the subject.
The primarypurpose of use cases are:
1. To describe the functionalrequirements of the system, resulting in an agreement between the
stakeholders and the software developerswho are developing the system.
2. To give a clear and consistent description of what the system should do.
3. To provide a basis for conducting system tests to verifywhether the system worksappropriately or
not.
4. To provide the ability to transformfunctionalrequirementsinto classes and operations in the
system.
Use Case:
A use case represents the functionalityprovided by the system to the user. A use case isdefined as “a
set of actions performed by the system, whichproduces an observable resultthatis, typically, of some
value to one or more actors or other stakeholders of the system”. The actions can
UNIFIED MODELLING LANGUAGE UNIT-4
includecommunicatingwithotheractors or systems as well as performingcalculationsinside the
system. The characteristics of a use case are:
1. A use case isalwaysinitiated by an actor.
2. A use case provides value to an actor.
3. A use case iscomplete.
Use cases are connected to actorsthrough associations, which are sometimesreferred to as
communication associations. Associations representwhichactors the use case iscommunicatingwith.
The association shouldalwaysbebinary, implying a dialogbetween the actor and system.
A use case is a classifier, not an instance. A use case represents the functionality as a wholewith
possible alternatives, errors and exceptions that can occurduring the execution of the use case. An
instance of the use case isknown as a scenario, whichrepresents a specificexecutionpaththrough the
system.
Example: Consider a online shopping system,
Use case: Purchase Product
Scenario: A user namedsuryapurchases a product, gaming console by usingdebitcardpayment
option.
The graphical representation of a use case is a solid ellipse with the use case name specified inside
the ellipse. A use case generally placed inside the system boundary and is always connected to an
actor using an association relationship. The name of the use case is generally a phrase rather a one
word label. The name can be a simple name or a path name as shown in the below example:
Actors:
An actoris one whichinteracts or uses the system (subject). An actorsends or receives messages
from the system. Actor can beeither a person or another system (computer or application). An
actoris a classifier, not an instance. An actorrepresents a role, not an individual user of the system.
For example, in an online shopping system, if rameshwants to purchase a product,
hisrolewillbebuyer.
An actor has a name, and the nameshouldreflect the actor’srole. The nameshould not represent an
instance of the actor or the functionality of an actor. A use case isalwaysinitiated by an
actorthatsends a message to it. This message isalsoknown as stimulus. Actors maybe of two types:
active actors and passive actors. Active actors or thosewhichinitiates a use case and passive actors
are thosewhichparticipate in a use case but neverinitiateit.
Actor can be represented with a class symbol stereotyped as <<actor>>. Actor has a standard
stereotype icon known as the “stickman”. An actor can have both attributes and behavior.
Flow of Events:
An extend relationship between use cases means that the extending use case extends the behavior of
the base use case. Such relationship is graphically represented as dependency stereotyped with
exclude. In a extend relationship, the base use case may exist on its own but at certain points its
behavior may be extended by the behavior of another use case. The extend relationship is used to
separate the optional behavior.
Consider the following which illustrates the use of generalization, include and extend relationships
between use cases:
Common Properties:
Use case diagramssharessomecommonpropertieswith the rest of the UML diagrams like a
namewhich identifies a use case diagram and the graphical content whichis a projection into a
model.
Content:
Use case diagramscommonlycontain:
Use cases
Actors
Dependency, generalization and association relationships
Like all otherdiagrams, use case diagramsmaycontain notes and constraints. Theymayalsocontain
packages or subsystems, which are used to group elements of your model intolargerchunks.
Common Uses:
Whenwe model the static use case view of a system, weapply use case diagrams in one of the
twoways:
To model the context of a system
UNIFIED MODELLING LANGUAGE UNIT-4
To model the requirements of a system
Activity Diagrams
Introduction:
An activitydiagramis like a flowchart, representing flow of control fromactivity to activity, whereas,
the interaction diagrams focus on the flow of control fromobject to object. Activitiesresult in some
action, whichis made up of executableatomic computations thatresult in a change of state of the
system or the return of a value. Actions involvecallinganotheroperation, sending a signal, creating
or destroying an object or some pure computation, such as evaluating an expression.
Common Properties:
An activitydiagramshares the samecommonproperties as do all other UML diagrams like a
namewhichisused to uniquelyidentify the diagram and the graphical content whichis a projection
into the model.
In contrast, activity states can be further decomposed, their activity being represented by other
activity diagrams. Activity states are non-atomic and can be interrupted, considered to take some
duration to complete. There is no difference in the notation of activity states and action states except
that the activity states may have additional information like entry and exit actions as shown below:
Transitions:
When the action or activity completes, the flow of control passes immediately to the next action or
activity state. This flow is represented as transitions to show the path from one action or activity
state to the next action or activity state. In UML, a transition is represented as a simple directed line.
A flow of control has to start and end someplace. Therefore, as shown in the above figure, we can
specify the initial state (solidball) and stop state (asolidballinside a hollowcircle).
Branching:
UNIFIED MODELLING LANGUAGE UNIT-4
Like in flowcharts, we can include a branch, which specifies alternate paths taken based on some
Boolean expression which is also known as a guard condition. In UML, a branch is represented as a
diamond. A branch may have one incoming transition and two or more outgoing transitions. Across
all these outgoing transitions, guards should not overlap, but they should cover all possibilities.
Swimlanes:
In activity diagrams, the activity states can be divided into logical groups, each group representing
the object responsible for the activities. In UML, each group is known as a swimlane because,
visually, each group is divided from its neighbor by a vertical solid line as shown in the below
figure. Each swimlane has its own name. In an activity diagram partitioned into swimlanes, every
activity belongs to exactly one swimlane, but transitions may cross lanes.
Modeling an operation:
To model an operation:
1. Collect the abstractions involved in an operation like: parameters, attributes of the enclosing class
and the neighboring class.
2. Identify the operation’s pre-conditions and the operation’s post-conditions.
3. Beginning at the operation’s initial state, define the actions and activities and renderthem as
action states and activity states respectively.
4. Use branching as necessary to specifyconditionalpaths and iteration.
5. If thisoperationisowned by an active class, use forking and joining as necessary to specifyparallel
flows of control.