Duration : 3 hrs
1
RamakantSoni
Assistant Professor
Dept. of Computer Science
B K Birla Institute of Engineering & Technology, Pilani, India
Ramakant Soni @ BKBIET PIlani
Class Diagram Overview
ClassdiagramisonetypeofUMLstructurediagram
whichshowsstructureofthedesignedsystematthe
levelofclassesandinterfaces,showstheirfeatures,
constraintsandtheirrelationships-associations,
generalizations,dependencies,etc.
Ramakant Soni @ BKBIET PIlani 2
ClassName
attributes
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.
operations
Ramakant Soni @ BKBIET PIlani
Person
name : String
address : Address
birthdate : Date
Anattributeisanamedpropertyofaclass
thatdescribestheobjectbeingmodeled.
Intheclassdiagram,attributesappearinthebirthdate : Date
ssn : Id
Intheclassdiagram,attributesappearinthe
secondcompartmentjustbelowthename-
compartment.
Ramakant Soni @ BKBIET PIlani
Person
name : String
address : Address
Attributesareusuallylistedintheform:
attributeName:Type
Aderivedattributeisonethatcanbe
computedfromotherattributes,butdoesn’t
actuallyexist.
address : Address
birthdate: Date
/ age : Date
ssn : Id
Forexample,aPerson’sagecanbe
computedfromhisbirthdate.Aderived
attributeisdesignatedbyapreceding‘/’as
in:
/age:Date
Ramakant Soni @ BKBIET PIlani
Person
+ name : String
# address : Address
Attributes can be:
+ public
# protected
-private
# address : Address
# birthdate : Date
/ age : Date
-ssn : Id
-private
/ derived
Ramakant Soni @ BKBIET PIlani
Person
name : String
address : Address
birthdate : Datebirthdate : Date
ssn : Id
Eat()
Sleep()
Work()
Play()
Operations describe the class behavior
and appear in the third compartment.
Ramakant Soni @ BKBIET PIlani
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
Ramakant Soni @ BKBIET PIlani
In UML, object interconnections (logical or physical), are modeled as
relationships.
There are five kinds of relationships in UML:
•dependencies
•generalizations
•associations
•Inheritence
•realization
Ramakant Soni @ BKBIET PIlani
A dependencyindicates a semantic relationship between two or
more elements. The dependency from CourseScheduleto Course
exists because Courseis used in both the addand removeoperations
of CourseSchedule.
CourseSchedule
add(c : Course)
remove(c : Course)
Course
Ramakant Soni @ BKBIET PIlani
Person
Ageneralizationconnectsasubclasstoits
superclass.
Itdenotesaninheritanceofattributesand
behaviorfromthesuperclasstothebehaviorfromthesuperclasstothe
subclassandindicatesaspecializationin
thesubclassofthemoregeneralsuper
class.
Student
Ramakant Soni @ BKBIET PIlani
Student
UML permits a class to inherit from multiple superclasses, although some
programming languages (e.g.,Java) do not permit multiple
inheritance.
Employee
TeachingAssistant
Ramakant Soni @ BKBIET PIlani
If two classes in a model need to communicate with each other, there
must be link between them.
An associationdenotes that link.
InstructorStudent
Ramakant Soni @ BKBIET PIlani