Unit 2
Unit 2
Unit 2
Prepared By
Shruti Bharadwaj
Assistant Professor,UCER,Praygraj
INDEX
• Class Diagram
• Object Diagram
UML - Diagrams
There are two broad categories of diagrams and they are again further
divided into subcategories −
• Structural Diagrams
• Behavioral Diagrams
Structural Diagrams
The structural diagrams represent the static aspect of the system.
These static aspects represent those parts of a diagram, which forms
the main structure and are therefore stable.
These static parts are represented by classes, interfaces, objects,
components, and nodes. The four structural diagrams are −
➢Class diagram
➢Object diagram
➢Component diagram
➢Deployment diagram
➢Package Diagram
Behavioral Diagrams
Behavioral diagrams basically capture the dynamic aspect of a system.
Dynamic aspect can be further described as the changing/moving parts
of a system.
UML has the following five types of behavioral diagrams −
➢Use case diagram
➢Sequence diagram
➢Collaboration diagram
➢State chart diagram
➢Activity diagram
Class Diagram
Class diagrams models the analysis and design of the static
view of an application. It captures the key abstractions of the
system at the first level, and is later refined with details of
every abstraction for reference.
UML Class Notation
• A class is a rectangle divided into three parts
– Class name
– Class attributes (i.e. data members, variables)
– Class operations (i.e. methods)
• Modifiers
– Private: -
– Public: +
– Protected: #
– Static: Underlined (i.e. shared among all members of the class)
• Abstract class: Name in italics
Employee
-Name : string
+ID : long
#Salary : double
+getName() : string
+setName()
-calcInternalStuff(in x : byte, in y : decimal)
Class diagram
◼ A class diagram depicts classes and their interrelationships
University Person
0..1 *
employer teacher
Multiplicity Role
Symbol Meaning
1 One and only one Role
0..1 Zero or one “A given university groups many people;
M.. From M to N (natural language)
some act as students, others as teachers.
N A given student belongs to a single
* From zero to any positive integer
university; a given teacher may or may not
0..* From zero to any positive integer be working for the university at a particular
1..* From one to any positive integer time.”
Association: Model to Implementation
* 4
Student Course
has enrolls
class Student {
Course enrolls[4];
}
class Course {
Student have[];
}
Link and Association
employment
◼ N-array association:
company Worker
Contract
Association End Names
Example
Whole Class Part Classes
A number of different chess boards: Each
square belongs to only one board. If a
chess board is thrown away, all 64
squares on that board go as well.
OO Relationships
Aggregation vs. Composition
◼ Composition is really a strong form of association
➢ components have only one owner
➢ components cannot exist independent of their owner
➢ components live or die with their owner
➢ e.g. Each car has an engine that can not be shared with other cars.
◼ Aggregations
may form "part of" the association, but may not be essential to it. They
may also exist independent of the aggregate. e.g. Apples may exist
independent of the bag.
Concrete Class
◼ Instantiable – which can have direct instances.
◼ It may have abstract subclasses – But in turn must have concrete
descendants
◼ Only concrete classes may be leaf classes in an inheritance tree.
Abstract Class
• Format is
– Instance name : Class name
– Attributes and Values
– Example:
Object Diagram
The collaboration diagram is used to show the relationship between the objects in a system.
Both the sequence and the collaboration diagrams represent the same information but differently.
Instead of showing the flow of messages, it depicts the architecture of the object residing in the
system as it is based on object-oriented programming.
An object consists of several features.
Multiple objects present in the system are connected to each other
The collaboration diagram, which is also known as a communication diagram, is used to portray the
object's architecture in the system.
Notations of a Collaboration Diagram
The main purpose of a use case diagram is to portray the dynamic aspect of
a system.
It accumulates the system's requirement, which includes both internal as
well as external influences.
It invokes persons, use cases, and several things that invoke the actors and
elements accountable for the implementation of use case diagrams.
It represents how an entity from the external environment can interact with a
part of the system.
How to draw a Use Case
diagram?
It is essential to analyze the whole system
before starting with drawing a use case
diagram, and then the system's
functionalities are found.
And once every single functionality is
identified, they are then transformed into
the use cases to be used in the use case
diagram.
After that, we will enlist the actors that will
interact with the system.
The actors are the person or a thing that
invokes the functionality of a system.
It may be a system or a private entity,
such that it requires an entity to be
pertinent to the functionalities of the
system to which it is going to interact.
Once both the actors and use cases are
enlisted, the relation between the actor
and use case/ system is inspected.
It identifies the no of times an actor
communicates with the system. Basically,
an actor can interact multiple times with a
use case or system at a particular instance
of time.
Following are some rules that must be followed while drawing a use
case diagram:
The system is used to define the scope of the use case and drawn as a
rectangle. This an optional element but useful when you’re visualizing large
systems.
For example, you can create all the use cases and then use the system
object to define the scope covered by your project. Or you can even use it
to show the different areas covered in different releases.
Package
Include relationship show that the behavior of the included use case is part
of the including (base) use case. The main reason for this is to reuse
common actions across multiple use cases. In some situations, this is done
to simplify complex behaviors. Few things to consider when using the
<<include>> relationship.
The base use case is incomplete without the included use case.
The included use case is mandatory and not optional.
banking system use case diagram to show include relationships as
well
Generalization of a Use Case
This is similar to the generalization of an
actor. The behavior of the ancestor is
inherited by the descendant. This is used
when there is common behavior between
two use cases and also specialized
behavior specific to each use case.
For example, in the previous banking
example, there might be a use case called
“Pay Bills”. This can be generalized to
“Pay by Credit Card”, “Pay by Bank
Balance” etc.
Use Case Diagram Guidelines for Better Use Cases
A use case diagram mainly consists of actors, use cases and relationships.
More complex larger diagrams can include systems and boundaries.
Actors
Give meaningful business relevant names for actors – For example, if
your use case interacts with an outside organization it’s much better to
name it with the function rather than the organization name. (Eg: Airline
Company is better than PanAir)
Primary actors should be to the left side of the diagram – This enables
you to quickly highlight the important roles in the system.
Actors model roles (not positions) – In a hotel both the front office
executive and shift manager can make reservations. So something like
“Reservation Agent” should be used for actor name to highlight the role.
External systems are actors – If your use
case is send-email and if interacts with the
email management software then the
software is an actor to that particular use
case.
Actors don’t interact with other actors – In
case actors interact within a system you need
to create a new use case diagram with the
system in the previous diagram represented
as an actor.
Place inheriting actors below the parent
actor – This is to make it more readable and
to quickly highlight the use cases specific for
that actor.
Use Cases
Names begin with a verb – A use case
models an action so the name should
begin with a verb.
Make the name descriptive – This is to
give more information for others who are
looking at the diagram. For example “Print
Invoice” is better than “Print”.
Highlight the logical order – For
example, if you’re analyzing a bank
customer typical use cases include open
account, deposit and withdraw. Showing
them in the logical order makes more
sense.
Place included use cases to the right of
the invoking use case – This is done to
improve readability and add clarity.
Place inheriting use case below parent
use case – Again this is done to improve
the readability of the diagram.
Relationships
Arrow points to the base use case when
using <<extend>>
<<extend>> can have optional extension
conditions
Arrow points to the included use case
when using <<include>>
Both <<extend>> and <<include>> are
shown as dashed arrows.
Actor and use case relationship don’t
show arrows.
A use case diagram depicting the Online Shopping website is given
below.
State diagrams are used to implement real-life working models and object-oriented systems in depth.
These diagrams are used to compare the dynamic and static nature of a system by capturing the
dynamic behavior of a system.
Statechart diagrams are used to capture the changes in various entities of the system from start to
end.
They are used to analyze how an event can trigger change within multiple states of a system.
state chart diagram represents the user authentication
process.
State Machine Diagram example: Toaster
state Diagram for modeling the behavior of the
DigitalClock
State Machine Diagram example: Computer
Testing
State Machine Diagram example: Human Life
Package Diagram
Source files
Executable files
Database tables
Scripts
DLL files
User manuals or documentation
Output files
Artifact Instances
<< device >>It is a node that represents a physical machine capable of performing computations.
A device can be a router or a server PC.
It is represented using a node with stereotype <<device>>.
In the UML model, you can also nest one or more devices within each other.
Following is a representation of a device in UML.
<< device >>It is a node that represents a physical machine capable of performing computations. A
device can be a router or a server PC. It is represented using a node with stereotype <<device>>.
In the UML model, you can also nest one or more devices within each other.
Following is a representation of a device in UML:
<< execution environment >>It is a node that represents an environment in which software is going
to execute. For example, Java applications are executed in java virtual machine (JVM). JVM is
considered as an execution environment for Java applications. We can nest an execution environment
into a device node. You can net more than one execution environments in a single device node.
Following is a representation of an execution environment in UML:
deployment diagram represents the working of HTML5 video player in the browser
How to draw a Deployment Diagram?