Professional Documents
Culture Documents
SUMMER 2021
MD. RAFI-UR-RASHID
LECTURER, DEPT. OF CSE, UIU
Why This Lesson?
It is a crucial task in OOP
What is a UML class diagram?
• A UML class diagram is a picture of the classes in an OO system
• their fields and methods
• connections between the classes that interact or inherit from each other
4
Class attributes (fields, instance variables)
visibility name : type [count] = default_value
Student
• Visibility +
+
name: int
email: String
+ public - DOB: String
/ Age: int
# protected # ID: int
~ courses[100]:Course
- private
~ package (default) +Student(n:String,dob:String)
/ derived + getTotalCredits():Course
• Method listed as name: return type # calculateTuition():double
+ calculateGPA(crs:Course[]):float
• Parameters listed as name: type
• Omit return type on constructors
and when return type is void
5
Diagram of a single class Class name on top
• write «interface» on top of interfaces' names
• use italics for an abstract class name
6
Relationships between class
• Generalization: an inheritance relationship
• inheritance between classes
• interface implementation
• Association: a usage relationship
• dependency
• aggregation
• composition
7
Generalization relationships <<interface>>
Shape
+ Rectangle(x:int,y:int)
+ distance(r:Rectangle):double
8
Association (usage) relationships
9
Association multiplicities
One to one One to many
Each car has exactly one engine Each book has many pages
Each engine belongs to exactly one car Each page belongs to exactly one book
11