Class Relationships: Based On Slides of Dr. Norazah Yusof
Class Relationships: Based On Slides of Dr. Norazah Yusof
Lecture 18
Based on Slides of Dr. Norazah Yusof
Aggregation
Composition
Inheritance
Association
Association represents a general binary relationship
that describes an activity between two classes.
Student
5..60
Take
* Course
0..3
Teach
/** Constructors */
/** Methods */
/** Constructors */
/** Methods */
1
Teacher
Faculty
Association
Student
5..60
Course
navigability.
No arrow implies bidirectional navigability
4
Association
-name : String
-matrix : String
-courseList : Course[]
-numOfStudent : int
+ Student(String, String,
String)
+ getName() : String
+ getMatrix(): String
+ getNumOfStudent(): int
+ registerCourse(Course)
: void
+ printAllInfo():void
Course
-name : String
-code : String
- section : int
registerCourse(Course)
5..60
*
+ Course(String, String,
int)
+ getName() : String
Association
-name : String
-matrix : String
-courseList : Course[]
-numOfStudent : int
+ Student(String, String,
String)
+ getName() : String
+ getMatrix(): String
+ getNumOfStudent(): int
+ registerCourse(Course)
: void
+ printAllInfo():void
-name : String
-code : String
- section : int
registerCourse(Course)
5..60
*
+ Course(String, String,
int)
+ getName() : String
Association
-name : String
-matrix : String
-courseList : Course[]
-numOfStudent : int
+ Student(String, String,
String)
+ getName() : String
+ getMatrix(): String
+ getNumOfStudent(): int
+ registerCourse(Course)
: void
+ printAllInfo():void
Course
registerCourse(Course)
5..60
-name : String
-code : String
- section : int
*
+ Course(String, String,
int)
+ getName() : String
11
Course
-name : String
-code : String
- section : int
+ Course(String, String,
int)
+ getName() : String
Teach(Course)
0..3
+ Lecturer (String)
+ getName() : String
+ getNumOfCourse(): int
+ teach(Course): void
+ printAllInfo():void
12
Student
-name : String
-matrix : String
-courseList : Course[]
-numOfStudent : int
+ Student(String, String,
String)
+ getName() : String
+ getMatrix(): String
+ getNumOfStudent(): int
+ registerCourse(Student):
void
+ printAllInfo():void
Course
register(Course)
5..60
0..3
add(Student)
-name : String
* -code : String
1 - section : int
- stuList: Student[]
+ Course(String, String,
int)
+ getName() : String
+ addStudent(Course):
void
+ printAllInfo():void
/*methods*/}
13
14
16
17
Person
Supervisor
1
18
Name
Aggregation
Person
Address
19
/** Constructors */
/** Methods */
}
20
21
}
22
Aggregation relationship is represented as a data field in the aggregated class.
Composition
Form of aggregation.
For a relationship: contains a.
Strong ownership / binding.
Parts belong to one whole.
Parts do not change during execution.
Automobile
Motor
Transmission
Name
firstName : String
lastName : String
Name(String first, String last)
String getFirstName()
String getLastName()
String getFullName()
Address
street : String
city : String
state : String
zip : String
Address(String street, String city, String state, String zip)
String getStreet()
String getCity()
String getState()
String getZip()
String getFullAddress()
24
this.firstName=firstName;
this.lastName=lastName;
}
public String getFullName()
{
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
return street +'\n' + city+ ", " +state+ ' ' +zip ; }
26
return name; }
28
Self-Test
What is the appropriate relationship
31