Software Engineering Unit (3)
Software Engineering Unit (3)
UNIT NO. 03
OVERVIEW OF UML
TOPICS TO BE COVERED
⮚ Class Diagram
⮚ Object Diagram
⮚ Sequence Diagram
⮚ Activity Diagram
⮚ Component Diagram
⮚ Collaboration Diagram
⮚ Class Diagram
A UML Class Diagram provides a static view of a system by showing the types of objects,
their attributes, methods, and the relationships between them. It is widely used in object-
oriented software design to visualize, describe, and document different aspects of the system
and can also help generate code for software development.
A class diagram consists of three main sections, which help in representing the structure and
behavior of a system. Each section plays a key role in visualizing the system's objects and
their relationships.
The upper section contains the name of the class. This is the main identifier for the class
and represents a group of similar objects with shared attributes, behaviors, and relationships.
• Capitalize the first letter of the class name (e.g., Customer, Order).
The middle section contains the attributes of the class, which represent the properties or
data that define the characteristics of an object.
Characteristics of Attributes:
The lower section contains the methods (or operations) that describe the behavior of the
class. These are the functions that define how the class interacts with its attributes and other
objects.
Characteristics of Methods:
• Visibility: Similar to attributes, methods have visibility factors (+, -, #, ~) indicating how
accessible they are.
• List Format: Methods are listed one by one, each on a new line.
• Methods typically include:
o Method name (e.g., calculateTotal(), updateStock())
o Parameters (if any) inside parentheses
o Return type (optional), which indicates the data type the method will return.
1. Dependency
2. Generalization (Inheritance)
3. Association
Multiplicity
• Definition: Multiplicity defines the number of instances of one class that can be associated
with a single instance of another class. If no range is specified, the default multiplicity is one.
• Example: A hospital can admit multiple patients, meaning one hospital can have many
patients.
4. Aggregation
5. Composition
• Definition: Composition is a stronger form of aggregation where the child object’s existence
depends on the parent object. If the parent object is deleted, the child object also gets
deleted.
• Example: A ContactBook contains multiple Contacts. If the contact book is deleted, all its
contacts are also deleted.
Abstract Classes
• Example: Suppose there is an abstract class called Vehicle with a method drive().
Different subclasses like Car, Bike, and Scooter can implement the drive() method
according to their own behavior.
Summary of Relationships
These relationships help define the structure and interaction in object-oriented systems,
making it easier to visualize how different parts of the system work together.
⮚ Activity Diagram
• In UML, 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.
• Activity diagrams are mainly used as a flowchart that consists of activities performed
by the system. Activity diagrams are not exactly flowcharts as they have some
additional capabilities. These additional capabilities include branching, parallel flow,
swimlane, etc.
• The activity diagram helps in envisioning the workflow from one activity to another. It
put emphasis on the condition of flow and the order in which it occurs. The flow can
be sequential, branched, or concurrent, and to deal with such kinds of flows, the activity
diagram has come up with a fork, join, etc.
• In activity diagrams, the notations are like visual symbols that help represent different
elements and actions in a simple way.
Initial State
• The starting state before an activity takes place is depicted using the initial state
• An activity state can have multiple incoming and outgoing action flows. We use a line
with an arrow head to depict a Control Flow. If there is a constraint to be adhered to
while making the transition it is mentioned on the arrow.
For example: Here both the states transit into one final state using action flow symbols
i.e. arrows.
For example: We apply the conditions on input number to display the result :
If number is odd then display the number.
If number if even then display the error.
Guard
• A Guard refers to a statement written next to a decision node on an arrow sometimes
within square brackets.
• The statement must be TRUE/FASLE for the control to shift along a particular
direction. Guards help us know the constraints and conditions which determine the flow
of a process.
Fork
• Fork nodes are used to support concurrent activities. When we use a fork node when
both the activities get executed concurrently i.e. no decision is made before splitting
the activity into two parts. Both parts need to be executed in case of a fork statement.
We use a rounded solid rectangular bar to represent a Fork notation with incoming
arrow from the parent activity state and outgoing arrows towards the newly created
activities.
For example: In the example below, the activity of making coffee can be split into two
concurrent activities and hence we use the fork notation.
Join
• Join nodes are used to support concurrent activities converging into one. For join
notations we have two or more incoming edges and one outgoing edge.
For example: When both activities i.e. steaming the milk and adding coffee get
completed, we converge them into one final activity.
For example: In the diagram below: we can’t have both sides executing concurrently, but
they finally merge into one. A number can’t be both odd and even at the same time.
Swimlanes
• We use Swimlanes for grouping related activities in one column. Swimlanes group
related activities into one column or one row. Swimlanes can be vertical and horizontal.
Swimlanes are used to add modularity to the activity diagram. It is not mandatory to
use swimlanes. They usually give more clarity to the activity diagram. It’s similar to
creating a function in a program. It’s not mandatory to do so, but, it is a recommended
practice.
For example: Here different set of activities are executed based on if the number is odd or
even. These activities are grouped into a swimlane.
Time Event
• This refers to an event that stops the flow for a time; an hourglass depicts it. We can
have a scenario where an event takes some time to completed.
For example: Let us assume that the processing of an image takes a lot of time. Then it can
be represented as shown below.
⮚ Object Diagram
• Object diagrams are a visual representation in UML (Unified Modeling Language) that
illustrates the instances of classes and their relationships within a system at a specific
point in time. They display objects, their attributes, and the links between them,
providing a snapshot of the system’s structure during execution. Since object diagrams
depict behavior when objects have been instantiated, we can study the behavior of the
system at a particular instant.
o Object diagrams in UML are depicted using a simple and intuitive notation to
show a snapshot of a system at a specific point in time, displaying instances of
classes and their relationships.
• What is an Object?
o An object is a specific thing made from a general idea. If you think of a class as
a design for a toy (like a toy car), then an object is one of the actual toy cars
built from that design. Each toy car might have a different color or speed, but
they’re all built from the same basic design. In programming, an object is a real
piece of data created from the class, holding specific values.
• What is a Classifier?
o A classifier is a broad category that groups things with similar traits. For
example, in a zoo, you might have a section for mammals. “Mammals” is like
a classifier—it groups together animals like lions, elephants, and monkeys
because they share common features. In programming, a classifier helps group
objects that have similar properties, making it easier to manage and understand
them.
Link
• We use a link to represent a relationship between two objects. We represent the
number of participants on the link for each, at the end of the link. The term link is
used to specify a relationship between two instance specifications or objects. We
use a solid line to represent a link between two objects.
For Example – In the figure below, an object of class Student is linked to an object of class
College.
Dependency Relationships
• We use a dependency relationship to show when one element depends on another
element. A dependency is used to depict the relationship between dependent and
independent entities in the system.
o Any change in the definition or structure of one element may cause changes
to the other.
o This is a unidirectional kind of relationship between two objects.
o Dependency relationships are of various types specified with keywords like
Abstraction, Binding, Realization, Substitution and Usage are the types of
dependency relationships used in UML.
For example – In the figure below, an object of Player class is dependent (or uses) an object
of Bat class.
Association
• Association is a reference relationship between two objects (or classes). An
association line connects two object boxes, representing a relationship between
instances of two classes. We use association when one object references members
of the other object. Association can be uni-directional or bi-directional. We use an
arrow to represent association.
For example – The object of Order class is associated with an object of Customer class.
Aggregation
• Aggregation represents a “has a” relationship. We use a hollow diamond on the
containing object with a line which joins it to the contained object.
o Aggregation is a specific form of association.
o It is a kind of parent-child relationship however it isn’t inheritance.
o Aggregation occurs when the lifecycle of the contained objects does not
strongly depend on the lifecycle of container objects.
For example – A library has an aggregation relationship with books. Library has books or books
are a part of library. The existence of books is independent of the existence of the library.
Composition
• Composition is a type of association where the child cannot exist independent of
the other. We use a filled diamond on the containing object with a line which joins
it to the contained object. Composition is also a special type of association. It is also
a kind of parent child relationship but it is not inheritance. So whenever independent
existence of the child is not possible we use a composition relationship.
Consider the example of a boy Gurkaran: Gurkaran is composed of legs and arms. Here
Gurkaran has a composition relationship with his legs and arms. Here legs and arms can’t exist
without the existence of their parent object.
• Identify Objects: Identify specific instances or objects of each class that you want to
include in the diagram. These represent the actual things in your system.
• Create Object Boxes: Draw rectangles to represent the specific instances or objects of
each class. Write the name of each object inside the box.
• Add Attributes and Values: Inside each object box, list the attributes of that object along
with their specific values.
• Draw Relationships: Connect the object boxes with lines to represent relationships or
associations between instances. Use arrows to indicate the direction of the association
if necessary.
• Label Relationships: Label the relationships with multiplicity and role names if needed.
Label the association lines with a verb or phrase to describe the nature of the
relationship.
• Review and Refine: Review your Object diagram to ensure it accurately represents the
system’s structure and relationships. Refine the diagram as needed based on feedback
and requirements.
• Use Tools for Digital Drawing: While you can draw class diagrams on paper, using
digital tools can provide more flexibility and ease of modification. UML modeling
tools, drawing software, or even specialized diagramming tools can be helpful.
⮚ Collaboration Diagram
2. Actors:
What They Are: Actors are like the project leader or client who asks the team to
do something. They start the action, like asking the team to build a new feature.
- Example: The client asks John to write a piece of code, and then Emma to test
it.
3. Links:
What They Are: Links are the connections between the friends. It’s like drawing
a line from John to Emma to show that they’re communicating.
- Example: A line between John and Emma shows that John sends the code to
Emma for testing.
4. Messages:
What They Are: Messages are what the friends are saying to each other. For
example, John might say, “Emma, can you test this code?” This message has a
sequence, like who says what first.
- Example: John sends a message to Emma to start testing after he finishes
coding.
Examples:
- Organizing a Team Project: Visualize how each team member (like John and
Emma) communicates and shares tasks.
- Designing a System: See how different parts of a software system interact, like
how the login page talks to the database.
5. Draw the Diagram: Map out how each part (or person) is connected and how
they communicate.
- Shows Connections: It’s great for seeing how different parts of a system or
project are linked together.
- Easy to Understand: It simplifies understanding of who is connected to whom,
like mapping out friendships in a group.
Example: Imagine turning a list of steps (like a recipe) into a diagram that shows
which ingredients or tools interact with each other.
Drawbacks
- Can Get Complicated: If there are too many people (or parts), the diagram can
become messy, like a big group chat that’s hard to follow.
- Takes Time to Make: Creating these diagrams can be slow, especially if the
system or project is large.
⮚ Component Diagram
o Imagine building a machine with different parts, where each part has a
specific job and connects to others. In the same way, a component diagram
shows different pieces of a software system, like files, libraries, or
programs, and how they connect to make the system work. It helps you
understand what parts are needed and how they interact, without getting
into the details of how each part is made. It's useful for organizing and
understanding the structure of a system.
Notations
1. Component:
2. Interfaces:
3. Relationships:
4. Ports:
o Role: Represent specific interaction points on the boundary of a component
where interfaces are provided or required.
o Symbol: Small squares on the component boundary.
o Function: Allow for more precise specification of interaction points,
facilitating detailed design and implementation.
5. Artifacts:
o Role: Represent physical files or data that are deployed on nodes.
o Symbol: Rectangles with the artifact stereotype («artifact»).
o Function: Show how software artifacts, like executables or data files,
relate to the components.
6. Nodes:
o Role: Represent physical or virtual execution environments where
components are deployed.
o Symbol: 3D boxes.
o Function: Provide context for deployment, showing where components
reside and execute within the system’s infrastructure.
2. Identify Components:
- List Components: Identify the key parts of the system.
- Define Roles: Specify what each component does.
3. Define Interfaces:
4. Map Relationships:
- Connections: Show how components connect and depend on each other.
5. Identify Artifacts:
- List Artifacts: Identify files, executables, or documents associated with each
component.
- Map Usage: Show how components use these artifacts.
6. Identify Nodes:
- Deployment Locations: Determine where components will be deployed, like
on servers or devices.
A UML Use Case Diagram is a visual representation of the interactions between actors (users
or systems) and use cases (functions or features) within a system. It captures the dynamic
behavior of a system, showing what functionalities are provided and how external entities
interact with them. It is mainly used to understand system requirements and is essential for the
analysis phase of software development.
1. Gather System Requirements: It captures all functional requirements by showing the use
cases.
2. Depict External View: It shows how external users or systems (actors) interact with the
system.
3. Identify Influencing Factors: It helps recognize both internal and external factors affecting
the system.
4. Show Actor Interaction: It visualizes the interaction between various actors and the system.
1. Identify the System’s Functionalities: Before drawing, analyze the system and
identify its major functions. These will become your use cases.
2. Identify the Actors: List the entities (users, external systems) that will interact with
the system. Actors can be people, other systems, or devices that trigger the system’s
functionality.
3. Define the Relationships: Once you know the use cases and actors, define how the
actors interact with the use cases. An actor can interact with multiple use cases, and a
use case can involve multiple actors.
4. Assign Names and Notations: Each actor and use case should have a clear and
meaningful name. Use the appropriate UML notations to show actors, use cases, and
relationships.
• Actor: An external entity that interacts with the system (e.g., Customer, Admin).
Represented by a stick figure.
• Use Case: A specific function or feature of the system (e.g., Place Order, Register
Account). Represented by an oval.
• System Boundary: Represents the system or part of the system being modeled. It groups
related use cases.
• Relationships:
o Association: A line connecting actors and use cases to show interaction.
o Include: Shows that one use case includes the behavior of another (e.g., Checkout
includes Payment).
In an Online Shopping System, the Web Customer actor interacts with various use cases
like:
• Keep it Simple: The diagram should be easy to understand, focusing on the key interactions.
• Focus on Important Interactions: Highlight the most significant interactions between actors
and the system.
• Generalize Complex Diagrams: If the diagram becomes too complex, consider breaking it
down or generalizing it.
• Represent a Complete Module: Ensure that each use case diagram represents at least one
complete module or functionality of the system.
o Add to Cart.
o Checkout (which includes Customer Authentication and Payment).
• Relationships:
o Include: Checkout includes Payment.
o Extend: View Items can be extended by Add to Wish List for logged-in users.
This example shows how actors interact with a system to perform tasks like browsing items,
adding them to a cart, and making a purchase. Use cases like Checkout and Payment are
often reused across different parts of the system using include and extend relationships.
Conclusion
A UML Use Case Diagram helps in understanding the system's behavior by showing how
external entities (actors) interact with system functionalities (use cases). It provides a high-
level overview of the system and is a useful tool for gathering requirements and designing
systems efficiently.
➢ Sequence Diagram
A UML Sequence Diagram is a type of interaction diagram that shows how processes operate
with one another and in what order. It visualizes the flow of messages between different objects
in a system during a particular interaction. It is also known as an event diagram and helps
model dynamic behavior by portraying the sequence of interactions over time.
• Model High-Level Interactions: It captures how active objects in a system interact over
time.
• Model Object Interactions: It describes the communication between objects within a
system, especially in the context of realizing a use case.
• Depict Specific Scenarios: It can be used to model specific instances or generic interactions
between objects.
1. Lifeline:
o Represents an individual participant in the interaction.
o Drawn as a vertical bar below the object's name, showing the timeline of that
object.
2. Actor:
o Represents a role played by an external entity (e.g., user, system, or device)
interacting with the system.
o Actors are represented outside the system’s boundary, usually drawn as stick
figures.
3. Activation:
o A thin vertical rectangle on the lifeline that shows when an object is performing an
operation.
o The rectangle's height corresponds to the duration of the operation.
4. Messages:
o Messages are arrows that depict the communication between lifelines (objects or
actors).
o The sequence of messages is the core of the sequence diagram.
1. Call Message:
o Definition: Represents an invocation of an operation by a lifeline.
o Example: The order system returns an order confirmation message to the customer
lifeline.
3. Self Message:
o Definition: A message where a lifeline calls an operation on itself.
o Example: Modeling a message that takes 5 seconds to send data between two
systems.
Sequence Fragments
• Purpose: Sequence fragments make it easier to model complex interactions and maintain
the diagram.
Conclusion
A UML Sequence Diagram is a powerful tool for visualizing the flow of messages and
interactions between objects over time. It is commonly used for modeling system behavior
during specific use cases, helping both developers and stakeholders understand how parts of
the system work together.