Class Diagram
Designed by: Nadia Nazeer
Objectives
 Concept of class diagram
 Creating class diagram
Classes
ClassName
attributes
operations
A class is a description of a set of
objects that share the same attributes,
operations, relationships, and semantics.
Graphically, a class is rendered as a
rectangle, usually including its name,
attributes, and operations in separate,
designated compartments.
Class Names
ClassName
attributes
operations
The name of the class is the only required
tag in the graphical representation of a
class. It always appears in the top-most
compartment.
Class Attributes
Person
name : String
address : Address
birthdate : Date
ssn : Id
An attribute is a named property of a
class that describes the object being modeled.
In the class diagram, attributes appear in
the second compartment just below the
name-compartment.
Class Attributes (Cont’d)
Person
name : String
address : Address
birthdate : Date
/ age : Date
ssn : Id
Attributes are usually listed in the form:
attributeName : Type
A derived attribute is one that can be
computed from other attributes, but
doesn’t actually exist. For example,
a Person’s age can be computed from
his birth date. A derived attribute is
designated by a preceding ‘/’ as in:
/ age : Date
Class Attributes (Cont’d)
Person
+ name : String
# address : Address
# birthdate : Date
/ age : Date
- ssn : Id
Attributes can be:
+ public
# protected
- private
/ derived
Class Operations
Person
name : String
address : Address
birthdate : Date
ssn : Id
eat
sleep
work
play
Operations describe the class behavior
and appear in the third compartment.
Depicting Classes
Person
name : String
birthdate : Date
ssn : Id
eat()
sleep()
work()
play()
When drawing a class, you needn’t show attributes and operation
in every diagram.
Person
Person
name
address
birthdate
Person
eat
play
Person
Class Responsibilities
A class may also include its responsibilities in a class diagram.
A responsibility is a contract or obligation of a class to perform
a particular service.
SmokeAlarm
Responsibilities
-- sound alert and notify guard station
when smoke is detected.
-- indicate battery state
Relationships
In UML, object interconnections (logical or physical), are
modeled as relationships.
There are three kinds of relationships in UML:
• dependencies
• generalizations
• associations
Dependency Relationships
CourseSchedule
add(c : Course)
remove(c : Course)
Course
A dependency indicates a semantic relationship between two or
more elements. The dependency from CourseSchedule to
Course exists because Course is used in both the add and
remove operations of CourseSchedule.
Generalization Relationships
Person
A generalization connects a subclass
to its superclass. It denotes an
inheritance of attributes and behavior
from the superclass to the subclass and
indicates a specialization in the subclass
of the more general superclass.
Student
Generalization Relationships
(Cont’d)
Student
UML permits a class to inherit from multiple super classes,
although some programming languages (e.g., Java) do not permit
multiple inheritance.
TeachingAssistant
Employee
Association Relationships
If two classes in a model need to communicate with each other,
there must be link between them.
An association denotes that link.
InstructorStudent
Association Relationships
(Cont’d)
We can indicate the multiplicity of an association by adding
multiplicity adornments to the line denoting the association.
The example indicates that a Student has one or more
Instructors:
InstructorStudent
1..*
Association Relationships
(Cont’d)
The example indicates that every Instructor has one or more
Students:
InstructorStudent
1..*
Association Relationships
(Cont’d)
We can also indicate the behavior of an object in an association
(i.e., the role of an object) using role names.
InstructorStudent
1..*1..*
learns fromteaches
Association Relationships
(Cont’d)
We can also name the association.
TeamStudent
membership
1..* 1..*
Association Relationships
(Cont’d)
We can specify dual associations.
TeamStudent
member of
1..*
president of1 1..*
1..*
Association Relationships
(Cont’d)
Associations can also be objects themselves, called link classes
or an association classes.
WarrantyProduct
Registration
modelNumber
serialNumber
warrentyCode
Example
Example
References
 http
://agilemodeling.com/artifacts/classDiagram.h
tm
 http://creately.com/diagram-
type/article/simple-guidelines-drawing-uml-
class-diagrams
 http://www.tutorialspoint.com/uml/uml_class
_diagram.htm
 https://www.smartdraw.com/class-diagram/
For Requesting more Slid Share Visit
nadianazeer5@gmail.com

Class diagrams