5 Class
5 Class
ME CSE(IT)
1
The class diagram provides a static
structure of all the classes that exist within
the system and the relationships in which
they participate
Class diagrams are used in:
• Analysis To build a conceptual domain model with
semantic associations between concepts
• Design Structural model of a design in terms of class
interfaces
• Implementation Source code documentation,
exposing the implementation
2
A common or improper noun implies a class
A proper noun or direct reference implies an object
(instance of a class)
A collective noun implies a class made up of groups of
objects from another class
An adjective implies an attribute
A “doing” verb implies an operation
A “being” verb implies a classification relationship
between n object and its class
A “having” verb implies an aggregation or association
relationship
A transitive verb implies an operationA predicate or
descriptive verb phrase implies an operation
An adverb implies an attribute of a relationship or an
operation
A class is a description of a set of objects that share the
same attributes, operations, relationships, and semantics
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
attributes compartment.
operations
An attribute is a named property of a
Person class that describes the object being modeled.
name : String
address : Address
birthdate : Date Person
/ age : Date
ssn : Id Attributes can be: + name : String
+ public # address : Addre
# protected # birthdate : Date
- private / age : Date
/ derived - ssn : Id
Person Operations describe the class behavior
and appear in the third compartment.
name : String
address : Address
birthdate : Date
ssn : Id
eat
sleep
work
play
Person Person Person
name : String
birthdate : Date
Person ssn : Id
name Person eat()
address sleep()
birthdate eat work()
play play()
There are three kinds of relationships in UML:
• Dependencies
• Generalizations
• Associations
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.
CourseSchedule
Course
add(c : Course)
remove(c : Course)
A generalization 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.
Person
Student
UML permits a class to inherit from multiple superclasses,
Student Employee
TeachingAssistant
An association denotes how classes communicate with each other
membership
Student Team
1..* 1..*
Member of
1..* 1..*
Student Team
1 Leader of 1..*
Associations can also be objects themselves, called link classes
or an association classes.
Registration
modelNumber
serialNumber
warrentyCode
Product Warranty
Aggregations and Compositions
Engine
Car
Transmission
A composition indicates a strong ownership and coincident
lifetime of parts by the whole (i.e., they live and die as a
whole). Compositions are denoted by a filled-diamond
adornment on the association.
1 1
Scrollbar
Window
Menu
1 1 .. *
Some instructors are professors, while others
have job title adjunct
Departments offer many courses, but a
course may be offered by >1 department
Courses are taught by instructors, who may
teach up to three courses
Instructors are assigned to one (or more)
departments
One instructor also serves a department chair
18
chairs
0..1
Department 1
assigned to 1..*
1..*
1..*
Instructor
1
offers
teaches
1..* 0..3
19
A CASE tool for storing and tracking problem
reports
◦ Each report contains a problem description and a
status
◦ Each problem can be assigned to someone
◦ Problem reports are made on one of the “artifacts”
of a project
◦ Employees are assigned to a project
◦ A manager may add new artifacts and assign
problem reports to team members
20
0..*
Assigned To Artifact
Employee 1..* Project 1
1
1 0..*
Managed By History Log
0..n
History Entry
Code Bug Report
-when : Date
-whatDone : string
21
22
is registered for>
Student Semester
1..*
0..* 1
0..8
1..*
teaches> Subject
Instructor
1..3 0..6
1..*
<works for
1
1 sponsors> 1..*
Department Course
24