UML Tutorial
What is UML:
UML (Unified Modeling Language) is a general-purpose, graphical modeling language in
the field of Software Engineering.
UML is used to specify, visualize, construct, and document the artifacts (major elements)
of the software system.
It was initially developed by Grady Booch, Ivar Jacobson, and James Rumbaugh in 1994-
95 at Rational software, and its further development was carried out through 1996. In
1997, it got adopted as a standard by the Object Management Group.
Characteristics of UML
The UML has the following features:
o It is a generalized modeling language.
o It is distinct from other programming languages like C++, Python, etc.
o It is interrelated to object-oriented analysis and design.
o It is used to visualize the workflow of the system.
o It is a pictorial language, used to generate powerful modeling artifacts.
UML building blocks:
UML is composed of three main building blocks, i.e., things, relationships, and diagrams.
Building blocks generate one complete UML model diagram by rotating around several
different blocks.
It plays an essential role in developing UML diagrams. The basic UML building blocks
are enlisted below:
1. Things
2. Relationships
3. Diagrams
Things:
Anything that is a real-world entity or object is termed as things. It can be divided into
several different categories:
Structural things
Behavioral things
Grouping things
An notational things
Structural things:
Nouns that depict the static behavior of a model is termed as structural things. They
display the physical and conceptual components. They include class, object, interface,
node, collaboration, component, and a use case.
Class:
A Class is a set of identical things that outlines the functionality and properties of an
object.
It also represents the abstract class whose functionalities are not defined. Its notation is as
follows;
Object:
An individual that describes the behavior and the functions of a system.
The notation of the object is similar to that of the class; the only difference is that the
object name is always underlined and its notation is given below;
Interface:
A set of operations that describes the functionality of a class, which is implemented
whenever an interface is implemented.
Collaboration:
It represents the interaction between things that is done to meet the goal. It is symbolized
as a dotted ellipse with its name written inside it.
Use case:
Use case is the core concept of object-oriented modeling. It portrays a set of actions
executed by a system to achieve the goal.
Actor:
It comes under the use case diagrams. It is an object that interacts with the system, for
example, a user.
Component:
It represents the physical part of the system.
Node:
A physical element that exists at run time.
Behavioral Things:
They are the verbs that encompass the dynamic parts of a model.
It depicts the behavior of a system. They involve state machine, activity diagram,
interaction diagram, grouping things, annotation things
State Machine:
It defines a sequence of states that an entity goes through in the software development
lifecycle.
It keeps a record of several distinct states of a system component.
Activity Diagram: It portrays all the activities accomplished by different entities of a system. It
is represented the same as that of a state machine diagram. It consists of an initial state, final
state, a decision box, and an action notation.
Interaction Diagram: It is used to envision the flow of messages between several components
in a system.
Grouping Things:
It is a method that together binds the elements of the UML model. In UML, the package
is the only thing, which is used for grouping.
Package:
Package is the only thing that is available for grouping behavioral and structural things.
Annotation Things:
It is a mechanism that captures the remarks, descriptions, and comments of UML model
elements. In UML, a note is the only an-notational thing.
Note:
It is used to attach the constraints, comments, and rules to the elements of the model. It is
a kind of yellow sticky note.
Relationships:
It illustrates the meaningful connections between things. It shows the association between
the entities and defines the functionality of an application.
There are four types of relationships given below:
Dependency:
Dependency is a kind of relationship in which a change in target element affects the
source element, or simply we can say the source element is dependent on the target
element.
It is one of the most important notations in UML. It depicts the dependency from one
entity to another.
It is denoted by a dotted line followed by an arrow at one side as shown below,
Association:
A set of links that associates the entities to the UML model. It tells how many elements
are actually taking part in forming that relationship.
It is denoted by a dotted line with arrowheads on both sides to describe the relationship
with the element on both sides.
Generalization:
It portrays the relationship between a general thing (a parent class or superclass) and a
specific kind of that thing (a child class or subclass).
It is used to describe the concept of inheritance.
It is denoted by a straight line followed by an empty arrowhead at one side.
Realization:
It is a semantic kind of relationship between two things, where one defines the behavior
to be carried out, and the other one implements the mentioned behavior. It exists in
interfaces.
It is denoted by a dotted line with an empty arrowhead at one side.
Diagrams:
The diagrams are the graphical implementation of the models that incorporate symbols
and text. Each symbol has a different meaning in the context of the UML diagram.
There are thirteen different types of UML diagrams that are available in UML 2.0, such
that each diagram has its own set of a symbol.
And each diagram manifests a different dimension, perspective, and view of the system.
UML diagrams are classified into three categories that are given below:
1. Structural Diagram
2. Behavioral Diagram
3. Interaction Diagram
Structural Diagram:
It represents the static view of a system by portraying the structure of a system. It shows
several objects residing in the system.
Following are the structural diagrams given below:
Class diagram
Object diagram
Package diagram
Component diagram
Deployment diagram
Behavioral Diagram:
It depicts the behavioral features of a system. It deals with dynamic parts of the system. It
encompasses the following diagrams:
Use case diagram
Activity diagram
State machine diagram
Interaction diagram:
It is a subset of behavioral diagrams. It depicts the interaction between two objects and
the data flow between them.
Following are the several interaction diagrams in UML:
Timing diagram
Sequence diagram
Collaboration diagram
UML-Diagrams
The UML diagrams are categorized into structural diagrams, behavioral diagrams.
The diagrams are hierarchically classified in the following figure:
UML Class Diagram:
The class diagram depicts a static view of an application. It represents the types of objects
residing in the system and the relationships between them.
A class consists of its objects, and also it may inherit from other classes. A class diagram
is used to visualize, describe, document various different aspects of the system, and also
construct executable software code.
It shows the attributes, classes, functions, and relationships to give an overview of the
software system.
Purpose of Class Diagrams:
1. It analyses and designs a static view of an application.
2. It describes the major responsibilities of a system.
3. It is a base for component and deployment diagrams.
4. It incorporates forward and reverse engineering.
Class Diagram Example:
A class diagram describing the sales order system is given below.
UML Component Diagram:
A component diagram is used to break down a large object-oriented system into the
smaller components, so as to make them more manageable.
It models the physical view of a system such as executables, files, libraries, etc. that
resides within the node.
It visualizes the relationships as well as the organization between the components present
in the system. It helps in forming an executable system.
A component is a single unit of the system, which is replaceable and executable. The
implementation details of a component are hidden, and it necessitates an interface to
execute a function.
It is like a black box whose behavior is explained by the provided and required interfaces.
Notation of a Component Diagram
a) A component
b) A node
Purpose of a Component Diagram
Since it is a special kind of a UML diagram, it holds distinct purposes.
It describes all the individual components that are used to make the functionalities, but
not the functionalities of the system.
It visualizes the physical components inside the system. The components can be a library,
packages, files, etc.
The component diagram also describes the static view of a system, which includes the
organization of components at a particular instant.
The collection of component diagrams represents a whole system.
Purpose of the component diagram:
1. It envisions each component of a system.
2. It constructs the executable by incorporating forward and reverse engineering.
3. It depicts the relationships and organization of components.
Example of a Component Diagram
A component diagram for an online shopping system is given below:
UML Deployment Diagram:
The deployment diagram visualizes the physical hardware on which the software will be
deployed. It portrays the static deployment view of a system.
It involves the nodes and their relationships.
It ascertains how software is deployed on the hardware. It maps the software architecture
created in design to the physical system architecture, where the software will be executed
as a node.
Since it involves many nodes, the relationship is shown by utilizing communication
paths.
Notations of Deployment Diagram:
The deployment diagram consists of the following notations:
1. A component
2. An artifact
3. An interface
4. A node
Purpose of Deployment Diagram:
The main purpose of the deployment diagram is to represent how software is installed on
the hardware component.
It depicts in what manner a software interacts with hardware to perform its execution.
Both the deployment diagram and the component diagram are closely interrelated to each
other as they focus on software and hardware components.
The component diagram represents the components of a system, whereas the deployment
Example of a Deployment diagram:
UML Use Case Diagram:
A use case diagram is used to represent the dynamic behavior of a system. It encapsulates
the system's functionality by incorporating use cases, actors, and their relationships.
It models the tasks, services, and functions required by a system/subsystem of an
application.
It depicts the high-level functionality of a system and also tells how the user handles a
system.
Purpose of Use Case Diagrams:
1. It gathers the system's needs.
2. It depicts the external view of the system.
3. It recognizes the internal as well as external factors that influence the system.
4. It represents the interaction between the actors.
Notations of Use case Diagram:
Use case:
Use case is the core concept of object-oriented modeling. It portrays a set of actions
executed by a system to achieve the goal.
Actor:
It comes under the use case diagrams. It is an object that interacts with the system, for
example, a user.
Example of a Use Case Diagram:
UML Sequence Diagram:
The sequence diagram represents the flow of messages in the system and is also termed
as an event diagram.
It helps in envisioning several dynamic scenarios. It portrays the communication between
any two lifelines as a time-ordered sequence of events, such that these lifelines took part
at the run time.
Purpose of a Sequence Diagram:
To model high-level interaction among active objects within a system.
To model interaction among objects inside a collaboration realizing a use case.
It either model’s generic interactions or some certain instances of interaction.
Notations of a Sequence Diagram:
Lifeline
An individual participant in the sequence diagram is represented by a lifeline. It is positioned at
the top of the diagram.
Actor
A role played by an entity that interacts with the subject is called as an actor.
Activation:
It is represented by a thin rectangle on the lifeline. It describes that time period in which an
operation is performed by an element.
Messages:
The messages depict the interaction between the objects and are represented by arrows. They are
in the sequential order on the lifeline.
Example of a Sequence Diagram:
UML Activity Diagram:
The activity diagram is used to demonstrate the flow of control within the system rather
than the implementation.
It models the concurrent and sequential activities. The activity diagram helps in
envisioning the workflow from one activity to another.
Purpose of Activity Diagram:
To graphically model the workflow in an easier and understandable way.
To model the execution flow among several activities.
To model comprehensive information of a function or an algorithm employed within the
system.
To model the business process and its workflow.
To envision the dynamic aspect of a system.
Notations of an Activity Diagram:
Activities
The categorization of behavior into one or more actions is termed as an activity.
Activity partition /swimlane
The swimlane is used to cluster all the related activities in one column or one row
Forks
A fork node consists of one inward edge and several outward edges.
Join:
Join nodes are the opposite of fork nodes. A Logical AND operation is performed on all of the
inward edges as it synchronizes the flow of input across one single output (outward) edge.
Initial State: It depicts the initial stage or beginning of the set of actions.
Final State: It is the stage where all the control flows and object flows end.
Decision Box: It makes sure that the control flow or object flow will follow only one path.
Action Box: It represents the set of actions that are to be performed.
Example of Activity Diagram: