Lecture-7 UML and Interaction Diagrams PDF
Lecture-7 UML and Interaction Diagrams PDF
1. We refer to an operation by its name followed by its arguments in parentheses. If the arguments are not specified, we
suffix the name of the operation by a pair of empty parentheses. We describe operations in detail in the next section.
Modeling Concepts 39
Watch
time
date
SetDate(d) CalculatorWatch
calculatorState
EnterCalcMode()
InputNumber(n)
Figure 2-8 A UML class diagram depicting two classes, Watch and CalculatorWatch.
CalculatorWatch is a refinement of Watch, providing calculator functionality not found in normal watches.
In a UML class diagram, classes and objects are represented as boxes with three compartments: the first
compartment depicts the name of the class, the second depicts its attributes, the third its operations. The
second and third compartments can be omitted for brevity. An inheritance relationship is displayed by a line
with a triangle. The triangle points to the superclass, and the other end is attached to the subclass.
abstract classes sometimes do not correspond to an existing application domain concept, but
rather are introduced to reduce complexity in the model or to promote reuse.
A class defines the operations that can be applied to its instances. Operations of a
superclass can be inherited and applied to the objects of the subclass as well. For example, in
Figure 2-8, the operation SetDate(d), setting the current date of a Watch, is also applicable to
CalculatorWatches. The operation EnterCalcMode(), however, defined in the
CalculatorWatch class, is not applicable in the Watch class.
A class defines the attributes that apply to all its instances. An attribute is a named slot in
the instance where a value is stored. Attributes have a unique name within the class and the type.
Watches have a time and a date attribute. CalculatorWatches have a calculatorState
attribute.
An object is an instance of a class. An object has an identity and stores attribute values.
Each object belongs to exactly one class. In UML, an instance is depicted by a rectangle with its
name underlined. This convention is used throughout UML to distinguish between instances and
OrganicCompound
Benzene
Figure 2-9 An example of abstract class (UML class diagram). OrganicCompound is never instantiated
and only serves as a generalization class. The names of abstract classes are italicized.
40 Chapter 2 • Modeling with UML
«instanceOf»
simpleWatch1291:Watch Watch
calculatorWatch1515 «instanceOf»
:CalculatorWatch CalculatorWatch
Figure 2-10 A UML class diagram depicting instances of two classes. simpleWatch1291 is an instance
of Watch. calculatorWatch1515 is an instance of CalculatorWatch. Although the operations of Watch
are also applicable to calculatorWatch1515, the latter is not an instance of the former.
• State machine diagrams represent the behavior of nontrivial objects (Section 2.4.4).
• Activity diagrams are flow diagrams used to represent the data flow or the control
flow through a system (Section 2.4.5).
FRIEND
ReportEmergency
OpenIncident Dispatcher
FieldOfficer
AllocateResources
Figure 2-13 An example of a UML use case diagram for First Responder Interactive Emergency
Navigational Database (FRIEND), an accident management system. Associations between actors and use
cases denote information flows. These associations are bidirectional: they can represent the actor initiating
a use case (FieldOfficer initiates ReportEmergency) or a use case providing information to an actor
(ReportEmergency notifies Dispatcher). The box around the use cases represents the system boundary.
A Deeper View into UML 45
OpenIncident use case to create an incident report and initiate the incident handling. The
Dispatcher enters preliminary information from the FieldOfficer in the incident database
(FRIEND) and orders additional units to the scene with the AllocateResources use case.
For the textual description of a use case, we use a template composed of six fields (see
Figure 2-14) adapted from [Constantine & Lockwood, 2001]:
• The name of the use case is unique across the system so that developers (and project
participants) can unambiguously refer to the use case.
• Entry conditions describe the conditions that need to be satisfied before the use case is
initiated.
• The flow of events describes the sequence of interactions of the use case, which are to
be numbered for reference. The common case (i.e., cases that are expected by the user)
and the exceptional cases (i.e., cases unexpected by the user, such as errors and unusual
conditions) are described separately in different use cases for clarity. We organize the
steps in the flow of events in two columns, the left column representing steps
accomplished by the actor, the right column representing steps accomplished by the
system. Each pair of actor–system steps represents an interaction.
• Exit conditions describe the conditions satisfied after the completion of the use case.
• Quality requirements are requirements that are not related to the functionality of the
system. These include constraints on the performance of the system, its
implementation, the hardware platforms it runs on, and so on. Quality requirements are
described in detail in Chapter 4, Requirements Elicitation.
Use cases are written in natural language. This enables developers to use them for
communicating with the client and the users, who generally do not have an extensive knowledge
of software engineering notations. The use of natural language also enables participants from
other disciplines to understand the requirements of the system. The use of the natural language
allows developers to capture things, in particular special requirements, that cannot easily be
captured in diagrams.
Use case diagrams can include four types of relationships: communication, inclusion,
extension, and inheritance. We describe these relationships in detail next.
Communication relationships
Actors and use cases communicate when information is exchanged between them.
Communication relationships are depicted by a solid line between the actor and use case
symbol. In Figure 2-13, the actors FieldOfficer and Dispatcher communicate with the
ReportEmergency use case. Only the actor Dispatcher communicates with the use cases
OpenIncident and AllocateResources. Communication relationships between actors and use
cases can be used to denote access to functionality. In the case of our example, a FieldOfficer
and a Dispatcher are provided with different interfaces to the system and have access to
different functionality.
Include relationships
When describing a complex system, its use case model can become quite complex and can
contain redundancy. We reduce the complexity of the model by identifying commonalities in
different use cases. For example, assume that the Dispatcher can press at any time a key to
access a street map. This can be modeled by a use case ViewMap that is included by the use cases
OpenIncident and AllocateResources (and any other use cases accessible by the Dispatcher).
The resulting model only describes the ViewMap functionality once, thus reducing complexity of
A Deeper View into UML 47
the overall use case model. Two use cases are related by an include relationship if one of them
includes the second one in its flow of events. In use case diagrams, include relationships are
depicted by a dashed open arrow originating from the including use case (see Figure 2-15).
Include relationships are labeled with the string «include».
«include»
OpenIncident
ViewMap
«include»
AllocateResources
Quality requirements At any point during the flow of events, this use case can include the ViewMap
use case. The ViewMap use case is initiated when the Dispatcher invokes the
map function. When invoked within this use case, the system scrolls the map
so that location of the current Incident is visible to the Dispatcher.
Figure 2-16 Textual representation of include relationships of Figure 2-15. “Include” in bold for clarity.
We represent include relationships in the textual description of the use case with one of
two ways. If the included use case can be included at any point in the flow of events (e.g., the
ViewMap use case), we indicate the inclusion in the Quality requirements section of the use case
(Figure 2-16). If the included use case is invoked during an event, we indicate the inclusion in
the flow of events.
Extend relationships
Extend relationships are an alternate means for reducing complexity in the use case
model. A use case can extend another use case by adding events. An extend relationship
indicates that an instance of an extended use case may include (under certain conditions) the
A Deeper View into UML 49
Inheritance relationships
An inheritance relationship is a third mechanism for reducing the complexity of a
model. One use case can specialize another more general one by adding more detail. For
example, FieldOfficers are required to authenticate before they can use FRIEND. During early
stages of requirements elicitation, authentication is modeled as a high-level Authenticate use
case. Later, developers describe the Authenticate use case in more detail and allow for several
different hardware platforms. This refinement activity results in two more use cases:
AuthenticateWithPassword which enables FieldOfficers to login without any specific
hardware, and AuthenticateWithCard which enables FieldOfficers to login using a smart
card. The two new use cases are represented as specializations of the Authenticate use case
(Figure 2-19). In the textual representation, specialized use cases inherit the initiating actor and
the entry and exit conditions from the general use case (Figure 2-20).
Authenticate
WithPassword
Authenticate
Authenticate
WithCard
Figure 2-19 An example of an inheritance relationship (UML use case diagram). The Authenticate use
case is a high-level use case describing, in general terms, the process of authentication.
AuthenticateWithPassword and AuthenticateWithCard are two specializations of Authenticate.
sequence diagram for an actor setting his 2Bwatch one minute ahead. Each column represents an
object that participates in the interaction. Messages are shown by solid arrows. Labels on solid
arrows represent message names and may contain arguments. Activations (i.e., executing
methods) are depicted by vertical rectangles. The actor who initiates the interaction is shown in
the left-most column. The messages coming from the actor represent the interactions described
in the use case diagrams. If other actors communicate with the system during the use case, these
actors are represented on the right-hand side and can receive messages. Although for simplicity,
interactions among objects and actors are uniformly represented as messages, the modeler
should keep in mind that interactions between actors and the system are of a different nature
than interactions among objects.
Sequence diagrams can be used to describe either an abstract sequence (i.e., all possible
interactions) or concrete sequences (i.e., one possible interaction, as in Figure 2-34). When
describing all possible interactions, sequence diagrams provide notations for iterations and
conditionals. An iteration is denoted by a combined fragment labeled with the loop operator (see
Figure 2-35). An alternative is denoted by a combined fragment containing a partition for each
alternative. The alternatives are selected by guards on the first message of the partition ([i>0]
and [else] in Figure 2-35). If i is positive, the top alternative of the alt combined fragment is
executed and the op1() message is sent. Otherwise, the bottom alternative is executed and the
op2() message is sent.
pressButtons1And2()
blinkHours()
pressButton1() blinkMinutes()
pressButton2() incrementMinutes()
Time
refresh()
pressButtons1And2() commitNewTime()
stopBlinking()
a b c
alt
[i>0] op1()
[else] op2()
loop op3()
:2BwatchOwner
1:pressButtons1And2()
2:pressButton1()
3:pressButton2()
1.1:blinkHours()
4:pressButtons1And2()
2.1:blinkMinutes()
4.2:stopBlinking()
:2BwatchInput :2BwatchDisplay
3.1:incrementMinutes()
4.1:commitNewTime()
3.2:refresh()
:2BwatchTime
Figure 2-36 Example of a communication diagram: setting the time on 2Bwatch. This diagram represents
the same use case as the sequence diagram of Figure 2-34.
A Deeper View into UML 65
Figure 2-40 Refined state machine associated with the SetTime state (UML state machine diagram). lB
and rB correspond to pressing the left and right button, respectively.
activities and the object flows needed for coordinating the activities. Activity diagrams are
hierarchical: an activity is made out of either an action or a graph of subactivities and their
associated object flow. Figure 2-41 is an activity diagram corresponding to the state diagram in
Figure 2-37. Rounded rectangles represent actions and activities. Edges between activities
represent control flow. An activity can be executed only after all predecessor activities
completed.
Figure 2-41 A UML activity diagram for Incident. During the action HandleIncident, the Dispatcher
receives reports and allocates resources. Once the Incident is closed, the Incident moves to the
DocumentIncident activity during which all participating FieldOfficers and Dispatchers document the
Incident. Finally, the ArchiveIncident activity represents the archival of the Incident related
information onto slow access medium.
Control nodes coordinate control flows in an activity diagram, providing mechanisms for
representing decisions, concurrency, and synchronization. The main control nodes we use are
decisions, fork nodes, and join nodes.
Decisions are branches in the control flow. They denote alternatives based on a condition
of the state of an object or a set of objects. Decisions are depicted by a diamond with one or
more incoming open arrows and two or more outgoing arrows. The outgoing edges are labeled
with the conditions that select a branch in the control flow. The set of all outgoing edges from a
decision represents the set of all possible outcomes. In Figure 2-42, a decision after the
OpenIncident action selects between three branches: If the incident is of high priority and if it is
a fire, the FireChief is notified. If the incident is of high priority and is not a fire, the
PoliceChief is notified. Finally, if neither condition is satisfied, that is, if the Incident is of low
priority, no superior is notified and the resource allocation proceeds.
Fork nodes and join nodes represent concurrency. Fork nodes denote the splitting of the
flow of control into multiple threads, while join nodes denotes the synchronization of multiple
threads and their merging of the flow of control into a single thread. For example, in
Figure 2-43, the actions AllocateResources, Coordinate–Resources, and DocumentIncident
may all occur in parallel. However, they can only be initiated after the OpenIncident action, and
the ArchiveIncident action may only be initiated after all other activities have been completed.
Activities may be grouped into swimlanes (also called activity partitions) to denote the
object or subsystem that implements the actions. Swimlanes are represented as rectangles
enclosing a group of actions. Transitions may cross swimlanes. In Figure 2-44, the Dispatcher
swimlane groups all the actions that are performed by the Dispatcher object. The
FieldOfficer swimlane denotes that the FieldOfficer object is responsible for the
DocumentIncident action.
A Deeper View into UML 67
[lowPriority]
Open Allocate
Incident Resources
[fire & highPriority]
[not fire & highPriority]
Notify
Fire Chief
Notify
Police Chief
Figure 2-42 Example of decision in the OpenIncident process. If the Incident is a fire and is of high
priority, the Dispatcher notifies the FireChief. If it is a high-priority Incident that is not a fire, the
PoliceChief is notified. In all cases, the Dispatcher allocates resources to deal with the Incident.
Allocate
Resources
Document
Incident
Figure 2-43 An example of fork and join nodes in a UML activity diagram.
Dispatcher
Allocate
Resources
FieldOfficer
Document
Incident
Activity diagrams provide a task-centric view of the behavior of a set of objects. They can
be used: for example, to describe sequencing constraints among use cases, sequential activities
among a group of objects, or the tasks of a project. In this book, we use activity diagrams to
describe the activities of software development in Chapter 14, Project Management, and
Chapter 15, Software Life Cycle.