21-26. OOConcept and UML Diagram
21-26. OOConcept and UML Diagram
UML Diagrams
CSE Department
National Institute of Technology Rourkela
BASIC OBJECT-ORIENTATION CONCEPTS
2
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Object
Each object in an object-oriented program usually represents a
tangible real-world entity such as a library member, a book, an
issue register, etc.
3
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Class
A class is a description of a set of objects that share the same
attributes, operations, relationships, and semantics.
4
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Encapsulation
Encapsulation is the mechanism that binds together code and the data it
manipulates
Private data may not be accessed by a piece of the program that exists outside
the object.
Ref: https://www.edureka.co/blog/data-hiding-in-cpp/ 5
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Abstraction
Abstraction
It is a mechanism of hiding the implementation from the user &
exposing the interface.
The abstraction mechanism allows us to represent a problem in a
simpler way by considering only those aspects that are relevant to
some purpose and omitting all other details that are irrelevant.
7
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
A generalization hierarchy
Employee
8
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Types of Inheritance
Single Inheritance: A subclass derives from a single super-class.
Multiple Inheritance: A subclass derives from more than one super-
classes.
Multilevel Inheritance: A subclass derives from a super-class which in
turn is derived from another class and so on.
Hybrid Inheritance: A combination of
multiple and multilevel inheritance so
as to form a lattice structure.
Hierarchical Inheritance: A class has a
number of subclasses each of which
may have subsequent subclasses,
continuing for a number of levels, so
as to form a tree structure.
10
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Polymorphism [6]
Run Time or Late Binding
Virtual function
11
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Relationships
A relationship is a connection among things.
12
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Types of Class Relationships[1]
Relation
Aggregation
Composition
13
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Dependency
A dependency is a using relationship that states that a change in
specification of one thing.
for example, class Event may affect another thing that uses it (for
example, class Window), but not necessarily the reverse.
14
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Generalizations
Generalizations connect generalized classes to more-specialized
ones in what is known as subclass/superclass or child/parent
relationships.
15
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Association
An association is a structural relationship that specifies that
objects of one thing are connected to objects of another.
An association can have a name, and you use that name to
describe the nature of the relationship. So that there is no
ambiguity about its meaning.
16
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Aggregation
Sometimes, you will want to model a "whole/part“ relationship,
in which one class represents a larger thing (the "whole"), which
consists of smaller things (the "parts").
17
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Composition
Composition means that an object may be a part of only one
composite at a time.
18
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Association Types [1]
Car
aggregation: "is part of"
Symbolized by empty diamond 1
1 aggregatio
n
Engine
composition: is made of
Stronger version of aggregation Book
composition
The parts live and die with the whole 1
dependency: Depends on
dependency
Represented by dotted arrow.
Lottery Random
Ticket
19
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML Class Relation Notation Summary [1]
1..* 1
0..* 0..*
dependency
Object Association
n n
20
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Outline
UML
Static model
Dynamic model
UML Diagrams
Class diagram
21
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Object Modelling: UML
Object-oriented design (OOD) techniques are now extremely
popular:
Inception in early 1980’s and nearing maturity.
Widespread acceptance in industry and academics.
Unified Modelling Language (UML) became an ISO standard (ISO/IEC 19501)
in 2004.
22
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML Origin[1]
OOD in late 1980s and early 1990s:
Different software development houses were using different
notations.
23
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML Lineology[1]
Based Principally on:
OMT [Rumbaugh 1991]
UML
Booch’s
OOSE Methodology
24
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML as A Standard [1]
Adopted by Object Management Group (OMG) in 1997.
25
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Developments to UML[1]
UML continues to develop, due to:
Refinements
Making it applicable to new contexts
UML 2.0 2003
Application
to embedded
systems
UML 1.X
26
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Why are UML Models Required? [1]
Modelling is an abstraction mechanism:
Capture only important aspects and ignores the rest.
Different models obtained when different aspects are ignored.
An effective mechanism to handle complexity.
27
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML Diagrams[1]
Nine diagrams in UML1.x :
Used to capture 5 different views of a system.
28
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Views of a system [1]
User model view
This view represents the system (product) from the user’s (called
“actors” in UML) perspective.
29
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Views of a system[1]
Implementation model view
The structural and behavioral aspects of the system are represented
as they are to be built.
30
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Diagrams and views in UML
User’s View
-Use Case
Diagram
31
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML[1]
Class Diagram
set of classes and their relationships.
Object Diagram
set of objects (class instances) and their relationships
Component Diagram
logical groupings of elements and their relationships
Deployment Diagram
set of computational resources (nodes) that host each
component.
32
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML[1]
Use Case Diagram
high-level behaviors of the system, user goals, external entities: actors
Sequence Diagram
focus on time ordering of messages
Collaboration Diagram
focus on structural organization of objects and messages
Activity Diagram
flow of control between activities
33
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Some Insights on Using UML[1]
“UML is a large and growing beast, but you don’t need all of it in
every problem you solve…” – Martin Fowler
34
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Are All Views Required for Developing A Typical System?
NO
For a simple system:
Use case diagram, class diagram and one of the interaction diagrams
only.
Deployment diagram:
In case several hardware components used to develop the system.
35
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Static Structure
Static structure
key concepts of application, internal structure, relationships
37
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• Use Case Diagram
2. Event-based
Identify the external events that the system must respond to.
Relate the events to actors and use cases.
43
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Elements of Use Case
1. Actor
2. System or Subject
3. Association or Relationships
44
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Elements of Use Case: Actor
An actor represents a role
that an outsider takes on
when interacting with the
business system.
51
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Actors
Actors are rendered as stick figures.
You can define general kinds of actors (such as Customer) and
specialize them (such as Commercial Customer) using
generalization relationships.
52
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Use Cases and Flow of Events
A use case describes
what a system (or a subsystem, class, or interface) does but it does not
specify how it does it.
For example, in a human resources system, you might find the use
case Hire employee. This general business function might have
many possible variations.
You might hire a person from another company
You might transfer a person from one division to another
or you might hire a foreign national (which involves its own special rules).
Each of these variants can be expressed in a different sequence.
55
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Use Cases and Collaborations
The analysis of a system (which specifies behavior) should, as much as
possible, not be influenced by implementation issues (which specify how that
behavior is to be carried out).
Ultimately, however, you have to implement your use cases, and can be
created a society of classes and other elements that work together to
implement the behavior of this use case.
This society of elements, including both its static and dynamic structure, is
modeled in the UML as a collaboration.
Finding the minimal set of well-structured collaborations that satisfy the flow
of events specified in all the use cases of a system is the focus of a system's
architecture.
56
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Generalization
Generalization among use cases is just like generalization among
classes.
Here it means that the child use case inherits the behavior and
meaning of the parent use case
The child may add to or override the behavior of its parent and
the child may be substituted any place the parent appears
For example, in a banking system, you might have the use case Validate
User, which is responsible for verifying the identity of the user.
You might then have two specialized children of this use case
Check password and Retinal scan where both of which behave just like
Validate User and may be applied anywhere
57
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Include and Extend
Include Relationship
An include relationship between use cases means that the
base use case explicitly incorporates the behavior of another
use case at a location specified in the base.
58
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Include and Extend
Extend Relationship
An extend relationship between use cases means that the base use
case implicitly incorporates the behavior of another use case at a
location specified indirectly by the extending use case.
The base use case may stand alone, but under certain conditions, its
behavior may be extended by the behavior of another use case.
60
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Generalization, Include, and Extend
Main flow of events:
In this example, set priority is an extension point. A use case may have more than one
extension point (which may appear more than once), and these are always matched by
name.
Under normal circumstances, this base use case will execute without regard for the
priority of the order.
If this is an instance of a priority order, the extension point (set priority), the behavior
of the extending use case (Place rush order) will be performed, then the flow will
resume.
61
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Constructing Use Case Diagrams [7]
Collect information sources
Identify potential actors
Which partners and customers use the goods and services of the
business system?
Describe actors
Who or what do the actors represent?
62
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Constructing Use Case Diagrams[7]
Search for more business use cases
What else needs to be done?
63
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Modeling the Behavior of an Element
Identify the actors that interact with the element.
Candidate actors include groups that require certain behavior to
perform their tasks.
Consider also the exceptional ways in which each actor interacts with
the element.
Access camera
surveillance via t he cameras
Int ernet
homeowner
Set alarm
71
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Use-Case Diagram[2]
Arms/ disarms
syst em
homeow ner
Responds t o
alarm event
Encount ers an
error condit ion
72
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Use Case Model for Course Management Software [1]
At the beginning of each semester,
Each professor shall register the courses that he is going to teach.
Register
Course
offering
See
Course
List
Professor Show
registration
<<Extend>>
<<External>>
Register Billing System
course
Student
Drop
Course
Calendar
74
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Style Notes (Ambler, 2005)
Use case name should begin with a verb.
While use cases do not explicitly imply timing:
Order use cases from top to bottom to imply timing -- it improves
readability.
The primary actors should appear in the left.
Do not use arrows on the actor-use case relationship.
To initiate scheduled events include an actor called “time”, or
“calendar”
Do not show actors interacting with each other.
<<include>> should rarely nest more than 2 levels deep.
Use case diagrams represent functionality:
Should focus on the "what" and not the "how". 75
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Use Case Packaging
77
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Courseware System Description
Courseware overview:
78
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Courseware System Description
Courseware Actors and Use cases
79
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Courseware System Description
80
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Courseware System Description
81
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• Class Diagram
85
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML Class Representation [1]
A class represents a set of objects having similar attributes,
operations, relationships and behavior.
Class Name
Window
A class can
implicitly
size: Size have a few
Attributes visibility: boolean association
attributes
display()
Operations hide()
86
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Class Based Modeling
Class-based modeling represents the objects that the
System will manipulate,
The collaborations that occur between the classes that are defined.
87
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Class Based Modeling
Identify and analyze classes by examining the problem statement
88
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Identifying Analysis Classes [2]
Safe Home Security System: The Salient features are as follows:
Safehome security function enables the homeowner to configure the security
system when it is installed, monitors all sensors connected to the security system,
and interacts with the homeowner through the Internet, a PC , or a control panel.
During installation, the safehome control panel is used to program and configure
the system. Each sensor is assigned a number and type, a master password is
programmed for arming and disarming the system, and telephone number(s) are
input for dialing when a sensor event occurs.
When a sensor event is recognized, the software invokes an audiable alarm
attached to the system. After a delay time that is specified by the homeowner
during system configuration activities, the software dials a telephone number of a
monitoring service, provides information about the location, reporting the nature
of the events that has been detected.
The Homeowner receives security information via a control panel, the PC, or a
browser, collectively called an interface. The interface displays prompting
messages and system status information on the control panel, the pc, or the
browser window.
Nouns are underlined
Verbs/activty are italic and bold 90
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Identifying and Analysis Classes
Selecting Classes—Criteria
Retained information
If information about class must be remembered so that the
system can function.
Needed services
The potential class must have a set of identifiable operations
that can change the value of its attribute in some way.
Multiple attributes
The potential class must have multiple attribute.
Common attributes
A set of attributes apply to all instances of the classes.
Common operations
A set of operations apply to all instances of the classes.
Essential requirements
External entities that appear in the problem space and is
essential to the operation of any solution.
91
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Identifying Analysis Classes
List of potential SafeHome classes
Sensor
Control panel
System
Sensor event
Audible alarm
92
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Identify the attributes of each class
Attributes describe a class that has been selected for inclusion in
the requirements model.
93
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example UML classes
List of attributes for the System class defined for SafeHome
System
Operations define the behavior of an object.
System
sy stemID
verific ationPhoneNumber
sy stemStatus
delayTime
telephoneNumber
mas terPassw ord
temporaryPass word
attributes numberTries
program()
display()
reset()
query ()
modif y()
operations call()
95
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Class Types[2]
Entity classes, also called model or business classes, are extracted
directly from the statement of the problem (e.g., FloorPlan and Sensor).
Controller classes manage a unit of work from start to finish. That is,
controller classes can be designed to manage
the creation or update of entity objects;
the instantiation of boundary objects as they obtain information from
entity objects;
complex communication between sets of objects;
validation of data communicated between objects or between the user
and the application.
96
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Relationships
Relationships provide a pathway for communication between
objects
100
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Relationships
An association is a bi-directional connection between classes
An association is shown as a line connecting the related classes
101
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Relationships
ScheduleAlgorithm
RegistrationForm
RegistrationManager
addStudent(Course, StudentInfo)
Course
name
numberCredits
Student open()
name addStudent(StudentInfo)
major
Professor
name CourseOffering
tenureStatus
location
open()
addStudent(StudentInfo)
102
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Dependency
There are many kinds of dependencies.
access
A private import of the contents of another package. It is denoted by
keyword access.
call
Statement that a method of one class calls an operation of another
class, keyword is call.
derivation
Statement that one instance can be computed from another class,
keyword is derive.
permission
Permission for an element to use the contents of another element,
keyword is permit.
DisplayWindow Camera
<<access>>
{passw ord}
107
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Multiplicity and Navigation
Multiplicity defines how many objects participate in a relationships
Multiplicity is the number of instances of one class related to ONE
instance of the other class
For each association and aggregation, there are two multiplicity
decisions to make: one for each end of the relationship
109
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Multiplicity and Navigation
ScheduleAlgorithm
RegistrationForm
0..* RegistrationManager
1
addStudent(Course, StudentInfo)
1 Course
name
0..* numberCredits
Student open()
addStudent(StudentInfo)
major
1
3..10
1..*
Professor 4
tenureStatus 1 CourseOffering
0..4 location
open()
addStudent(StudentInfo)
110
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Inheritance
Inheritance is a relationships between a superclass and its subclasses
RegistrationManager
addStudent(Course, StudentInfo)
Course
name
RegistrationUser numberCredits
name Student open()
addStudent(StudentInfo)
major
Professor
CourseOffering
tenureStatus location
open()
addStudent(StudentInfo)
111
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
CRC Modeling [2]
Analysis classes have “responsibilities”
Responsibilities are the attributes and operations encapsulated by the
class
112
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
CRC Modeling[2]
Class :
Class :
Descri
p tion: :
Class
Descri p tion: :FloorPlan
Class
Descrip tion:
Re sponsibility:
Descrip tion: Collaborator :
Re sponsibility: Collaborator :
Re sponsibility: Collaborator :
Re sponsibility: Collaborator :
defines f loor plan name/type
manages f loor plan positioning
sc ales floor plan f or display
sc ales floor plan f or display
incorporates w alls, doors and window s Wall
show s position of vid eo cameras Camera
116
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Object Diagram [4]
object name object
Triangle: Polygon
117
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Object Diagram [1]
LibraryMember
LibraryMember LibraryMember
Mritunjay
B10028 Mritunjay
C-108, Laksmikant Hall B10028
1119 C-108, Laksmikant Hall
Mrituj@cse 1119
25-02-04 Mrituj@cse
25-03-06 25-02-04
NIL 25-03-06
NIL
IssueBook( );
findPendingBooks( );
findOverdueBooks( );
returnBook( );
findMembershipDetails( );
Different representations of
the LibraryMember object
118
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• Dynamic Model
UML Extensibility
https://www.visual-paradigm.com/guide/uml-unified-modeling-
language/uml-extexsibility-mechanism/
124
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• Interaction Diagram
127
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Interaction Diagrams (Cont.) [1]
The purpose of Interaction diagrams is to:
Model interactions between objects
Assist in understanding how a system (a use case) actually
works
Verify that a use case description can be supported by the
existing classes
Identify responsibilities/operations and assign them to classes
Interaction Diagram
Sequence diagram
Collaboration diagram
128
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
A First Look at Sequence Diagrams[1]
Captures how objects interact with each other:
To realize some behavior (use case execution).
Emphasizes time ordering of messages.
Can model: Simple sequential flow, branching, iteration, recursion, and
concurrency.
X-Axis (objects)
member: :Book
book:Book
LibraryMember Copy
Y-Axis (time)
message
Activation box
[ok] borrow(member)
setTaken(member)
condition
How do you show Mutually exclusive conditional messages?
129
129
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Develop One Sequence diagram for every use case[1]
Return
Book member: :Book
book:Book
LibraryMember Copy
Use ok = canBorrow()
Case borrow(book)
Borrow
Book
Book [ok] borrow(member)
setTaken(member)
Search
Book
130
130
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Elements of Sequence Diagram: dimension
Object Dimension: The horizontal axis shows the elements that are
involved in the interaction
Conventionally, the objects involved in the operation are listed from
left to right according to when they take part in the message
sequence. However, the elements on the horizontal axis may appear
in any order
Time Dimension: The vertical axis represents time proceedings (or
progressing) down the page. X-Axis (objects)
member: :Book
Y-Axis (time)
book:Book
LibraryMember Copy
borrow(book) Object
Life Line
ok = canBorrow()
message
Activation box
[ok] borrow(member)
setTaken(member)
condition
How do you show Mutually exclusive conditional messages?
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Elements of Sequence Diagram: Lifeline
Lifelines – A lifeline is a named element which depicts an
individual participant in a sequence diagram
The standard in UML for naming a lifeline follows the following
format – Instance Name : Class Name
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Elements of Sequence Diagram: Activation
Activations: A thin rectangle on a lifeline represents the period
during which an element is performing an operation.
The top and the bottom of the of the rectangle are aligned with
the initiation and the completion time respectively
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-sequence-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Elements of Sequence Diagram: Messages
Messages – Communication between objects is depicted using
messages. The messages appear in a sequential order on the
lifeline. We represent messages using arrows.
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Types of messages
Synchronous messages – A synchronous message waits for a
reply before the interaction can move forward. The caller
continues only when it knows that the receiver has processed the
previous message i.e. it receives a reply message.
We use a solid arrow head to represent a synchronous message.
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Types of messages
Reply Message – Reply messages are used to show the message
being sent from the receiver to the sender.
We represent a return/reply message using an open arrowhead
with a dotted line.
For example – Consider the scenario where the device requests a
photo from the user. Here the message which shows the photo
being sent is a reply message.
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Types of messages
Create message – We use a Create message to instantiate a new
object in the sequence diagram.
It is represented with a dotted arrow and create word labelled on
it to specify that it is the create Message symbol.
For example – The creation of a new order on a e-commerce
website would require a new object of Order class to be created.
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Types of messages
Delete Message – We use a Delete Message to delete an object.
When an object is deallocated memory or is destroyed within the
system we use the Delete Message symbol.
It is represented by an arrow terminating with a x.
For example – In the scenario below when the order is received
by the user, the object of order class can be destroyed.
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Types of messages
Self Message – Certain scenarios might arise where the object
needs to send a message to itself. Such messages are called Self
Messages and are represented with a U shaped arrow.
For example – Consider a scenario where the device wants to
access its webcam.
Recursive Message represents
the invocation of message of the
same lifeline.
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-sequence-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Types of messages
Found Message – A Found message is used to represent a
scenario where an unknown source sends the message.
It is represented using an arrow directed towards a lifeline from
an end point.
For example: Consider the scenario of a hardware failure.
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Types of messages
Lost Message – A Lost message is used to represent a scenario
where the recipient is not known to the system.
It is represented using an arrow directed towards an end point
from a lifeline.
For example: Consider a scenario where a warning is generated.
Since the destination is not known before hand, we use the Lost
Message symbol.
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Types of messages
Guards – To model conditions we use guards in UML.
They are used when we need to restrict the flow of messages on
the pretext of a condition being met.
Example: In order to be able to withdraw cash, having a balance
greater than zero is a condition that must be met as shown below.
Ref:https://www.geeksforgeeks.org/unified-modeling-language-uml-sequence-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: travel portal[1]
A user can use a travel portal to plan a travel
When the user presses the plan button, a travel agent applet
appears in his window
Once the user enters the source and destination,
The travel agent applet computes the route and displays the itinerary.
Travel agent widget disappears when user presses close button
:client
setItinerary
calculateRoute
<<destroy>>
145
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Syntax used in Sequence Diagram[1]
Conditional Message
[ variable = value ] message()
Message is sent only if clause evaluates to true
Iteration (Looping)
* [ i := 1..N ] message()
“*” is required; [ ... ] clause is optional
The message is sent many times to possibly multiple receiver
objects.
146
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Sequence Diagrams[1]
How to represent Mutually exclusive conditional invocations? If book is
available, invoke msg2 on ClassB else invoke msg3 on classC,
msg1( )
flag = checkBook()
147
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Elements of Sequence Diagram: Sequence Fragments
UML 2.0 introduces sequence (or interaction) fragments.
Sequence fragments make it easier to create and maintain
accurate sequence diagrams
A sequence fragment is represented as a box, called a combined
fragment, which encloses a portion of the interactions within a
sequence diagram
The fragment operator (in the top left cornet) indicates the type
of fragment
Fragment types: ref, assert, loop, break, alt, opt, neg
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-sequence-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Elements of Sequence Diagram: Sequence Fragments
Operator Fragment Type
Alternative multiple fragments: only the one whose
alt
condition is true will execute.
Optional: the fragment executes only if the
opt supplied condition is true. Equivalent to an alt only
with one trace.
par Parallel: each fragment is run in parallel.
Loop: the fragment may execute multiple times,
loop
and the guard indicates the basis of iteration.
Critical region: the fragment can have only one
region
thread executing it at once.
Negative: the fragment shows an invalid
neg
interaction.
Reference: refers to an interaction defined on
another diagram. The frame is drawn to cover the
ref
lifelines involved in the interaction. You can define
parameters and a return value.
Sequence diagram: used to surround an entire
sd
sequence diagram.
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-sequence-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Elements of Sequence Diagram: Sequence Fragments
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-sequence-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Hotel System
Below is a sequence diagram for making a hotel reservation. The object
initiating the sequence of messages is a Reservation window.
3. Reservation confirmed
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-sequence-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: search book
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-sequence-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• Collaboration Diagram
9: update
:Library
:Library
:Library :Library
:Library Boundary
Book
Renewal
Book :Book Member
Register
Book Controller
[reserved] Register
renewBook find MemberBorrowing
displayBorrowing
8: apology 10:
5: book selectBooks
bookSelected
confirm
Selected [reserved]
* find
[reserved] apology
[reserved]
1: renewBook update
:Library 7: apology
apology
:Library Book
Boundary 3: display Renewal confirm
Borrowing Controller
confirm
updateMemberBorrowing
4: selectBooks
2: findMemberBorrowing
12: confirm
:Library
updateMemberBorrowing
Member
155
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• State Diagram
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-state-machine-diagram/ 158
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Stateless vs. Stateful Objects[1]
State-independent (modeless):
Type of objects that always respond the same way to an event.
State-dependent (modal):
Type of objects that react differently to events depending on its state or
mode.
Use state machine diagrams for modeling objects with complex state-
dependent behavior.
159
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Stateful Classes[1]
Examples of some classes that have non-trivial state models:
Lift controller: Up, down, standstill
Game software controller: Novice, Moderate, Advanced…
GUI: Active, Inactive, clicked once, …
Robot controller: Obstacle, clear, difficult terrain…
160
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Robot: State Variables[1]
Movement: On, OFF
How many states in the
Direction: Forward, Backward, state machine model?
left, Right
Left hand: Raised, Down
Right hand: Raised, down
Head: Straight, turned left, turned right
Headlight: On, Off
Turn: Left, Right, Straight
Event-driven systems :
In contrast, depending on an event occurrence, corresponding handler is
activated
Programming these using traditional approach often not suitable, and
would at the least cause wasteful computations.
Represented using state machines.
162
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
State Chart Diagram Cont…
State chart avoids two problems of FSM:
State explosion
Lack of support for representing concurrency
163
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Difference between state diagram and flowchart
The basic purpose of a state diagram is to portray various
changes in state of the class and not the processes or commands
causing the changes.
However, a flowchart on the other hand portrays the processes
or commands that on execution change the state of class or an
object of the class.
165
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
State Machine Diagram[4]
A state machine is a graph of states and transitions.
Usually a state machine is attached to a class and describes the
response of an instance of the class to events that it receives.
State machines may also be attached to behaviors, use cases, and
collaborations to describe their execution.
Example of state machine diagram that shows
the history of a ticket to a performance.
166
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
State Machine Diagram[4]
Event
Any external influence from the rest of the world is summarized as an
event.
When the object detects an event, it responds in a way that depends on its
current state.
167
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Basic components of a statechart diagram
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.
Initial state – We use a black filled circle represent the initial state
of a System or a class.
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/about-state-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Substates
A state which has substates (nested states) is called a composite
state.
Substates may be nested to any level.
A nested state machine may have at most one initial state and
one final state.
Substates are used to simplify complex flat state machines by
showing that some states are only possible within a particular
context (the enclosing state).
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-state-machine-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Concurrent Sub-States and Regions
Concurrent Sub-states are independent and can complete at
different times and each sub-state is separated from the others
by a dashed line
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/about-state-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Concurrent State
The following state machine diagram models an auction with two
concurrent substates: processing the bid and authorizing the
payment limit.
History states allow the state machine to re-enter the last sub-
state that was active prior to leaving the composite state.
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/about-state-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Basic components of a statechart diagram
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.
Guard Condition
A transition may have Boolean expression called guard condition
It may reference attributes of the object that owns the state
machine and parameters of the trigger event
177
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: External Transition[4]
178
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Basic components of a statechart diagram
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/about-state-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Steps to draw a state diagram –
Identify the initial state and the final terminating states.
184
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: GUI Accepts only Balanced Parentheses [1]
Inputs are any characters
No nesting of parentheses
No “output” other than any state change
(
Balanced Not
start Balanced
end )
* *
186
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: GUI Accepts only upto 3 Nested parentheses[1]
How can we extend this machine to handle arbitrarily deep
nesting of parentheses?
end
( ( (
*
187
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
How to Model Nested parentheses?[1]
A state machine, but not just a state machine --- an EFSM
(/count++
(/count=1
start OK Wait
)[count==1] /count=0
end )[count>1]/ count--
188
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Developing State-charts from Use Cases[1]
Collect the actions, conditions and results from a use case
description.
190
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Assignment
Draw the state chart diagram of an elevator.
191
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• Activity Diagram
199
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Activity Diagram
We use Activity Diagrams to illustrate the flow of control in a
system and refer to the steps involved in the execution of a use
case.
https://www.geeksforgeeks.org/unified-modeling-language-uml-activity-diagrams/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Difference between Activity diagram and Flowchart
Flowcharts were typically invented earlier than activity diagrams.
Non programmers use Flow charts to model workflows.
For example: A manufacturer uses a flow chart to explain and
illustrate how a particular product is manufactured.
Final State or End State The state which the system reaches when
a particular process or activity ends is known as a Final State or
End State. We use a filled circle within a circle notation to
represent the final state in a state machine diagram. A system or a
process can have multiple final states.
Activity Node
It represents the execution of a statement in a procedure or the
performance of a step in a workflow
Basically any action or event that takes place is represented using an
activity
Consider the example – Here both the states transit into one final
state using action flow symbols i.e. arrows.
212
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Activity Diagram Notations
Time Event :We can have a scenario where an event takes some
time to complete.
For example – Let us assume that the processing of an image
takes a lot of time. Then it can be represented as shown below.
213
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Use Case Diagram [4]
214
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Processing an Order by the Box Office[4]
215
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Enrollment in the University
Send
Make Accept
Invoice Invoice Payment Payment
217
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: student admission process at IIT [1]
Academic Section Accounts Section Hostel Office Hospital Department
check
student
records
receive
fees
allot create
hostel hospital
record
register
receive
in
fees
course
conduct
allot medical
room examination
issue
identity card
218
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Uses and Abuses of Activity Diagrams[1]
Activity diagrams are useful to show behavior that spans over
multiple use cases:
Describe the workflow of the overall process.
219
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• Deployment Diagram
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-deployment-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Deployment Diagram elements
Graphically, a deployment diagram is a collection of vertices and
arcs.
Deployment diagrams commonly contain:
Nodes: 3-D box represents a node, either software or hardware
HW node can be signified with <<stereotype>>
Connections between nodes are represented with a line, with
optional <<stereotype>>
Nodes can reside within a node
Other Notations
Dependency
Association relationships.
May also contain notes and constraints.
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-deployment-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Deployment Diagram
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-deployment-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: deployment Diagram
https://www.tutorialspoint.com/uml/uml_deployment_diagram.htm
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• Component Diagram
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-component-diagram/ 227
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Component Diagram at a Glance
A component diagram breaks down the actual system under
development into various high levels of functionality.
Each component is responsible for one clear aim within the entire
system and only interacts with other essential elements on a
need-to-know basis.
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-component-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Basic Concepts of Component Diagram
A component represents a modular part of a system that
encapsulates its contents and whose manifestation is replaceable
within its environment.
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-component-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Basic Concepts of Component Diagram
Interface: In the example below shows two type of component
interfaces:
Provided interface symbols with a complete circle at their end
represent an interface that the component provides - this "lollipop"
symbol is shorthand for a realization relationship of an interface
classifier.
Required Interface symbols with only a half circle at their end (a.k.a.
sockets) represent an interface that the component requires (in
both cases, the interface's name is placed near the interface symbol
itself).
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-component-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Basic Concepts of Component Diagram
Port: Ports are represented using a square along the edge of the
system or a component. A port is often used to help expose
required and provided interfaces of a component.
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-component-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Relationships
Association: An association specifies a semantic relationship that can occur
between typed instances.
Aggregation: A kind of association that has one of its end marked shared as
kind of aggregation, meaning that it has a shared aggregation.
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-component-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example
The example shows the internal components of a larger component:
The data (account and inspection ID) flows into the component via the port on
the right-hand side and is converted into a format the internal components can
use. The interfaces on the right are known as required interfaces, which
represents the services the component needed in order to carry out its duty.
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-component-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example
The data then passes through several components via connections before it is
output at the ports on left. Those interfaces are known as provided interface,
which represents the services to deliver by the exhibiting component.
It is important to note that the internal components are surrounded by a large
'box' which can be the overall system itself or a subsystem or component of
the overall system (in this case the 'box' is a component itself).
https://www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-component-diagram/
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• UML Extensibility
238
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Profile [4]
Extensions are organized into profiles.
239
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
Example: Profile [4]
240
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML Extensibility: Stereotypes [4]
A stereotype is a kind of model element defined in the model itself.
241
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML Extensibility: Tagged values[6]
A tagged value extends the properties of a UML building block, allowing you to
create new information in that element’s specification
They allow you to extend the properties of a UML building block so that you
create new information in the specification of that element
242
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
UML Extensibility: Constraint[6]
A constraint is an extension of the semantics of a UML element,
allowing you to add new rules or to modify existing ones
They allow you to extend the semantics of a UML building block by adding
new rules or modifying existing ones
A constraint specifies conditions that must be held true for the model to be
well-formed.
243
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
References
1. Rajib Mall, “Fundamentals of Software Engineering”, 3rd edition, PHI, 2009
2. R.S. Pressman, “Software Engineering: A Practitioner's Approach”, 7th Edition,
McGraw
3. Sommerville, “ Introduction to Software Engineering”, 8th Edition, Addison-
Wesley, 2007
4. GRADY BOOCH, JAMES RUMBAUGH, IVAR JACOBSON, The Unified Modeling
Language User Guide, Addison Wesley, Reading, Massachusetts, May 2005
5. Pankaj Jalote, “An Integrated Approach to Software Engineering” Third
addition , Springer Press
6. Patrick Grässle, Henriette Baumann, and Philippe Baumann, “UML 2.0 in
Action A Project-Based Tutorial”, PACKT Publishing, Birmingham, UK, 2005.
7. https://www.visual-paradigm.com/guide/uml-unified-modeling-
language/uml-extexsibility-mechanism
8. http://www.cs.sjsu.edu/faculty/pearce/modules/lectures/uml2/index.htm
9. https://www.uml-diagrams.org/examples/online-shopping-domain-uml-
diagram-example.html
251
NIT Rourkela Puneet Kumar Jain “Software Engineering (CSE3004)”
• End of Chapter