OOP · OOP Relationships
Aggregation
After enrollment, they participate in the Learning process.
- After enrollment, they participate in the Learning process.
- The Java Course exists independently of the students.
- Likewise, the students continue to exist even if the course is removed.
- The relationship only represents an interaction (enrollment) and does not imply ownership.
Key Point: Association is a relationship where two independent objects work together while maintaining their own lifecycle. In this example, students and courses are associated through enrollment, but neither object depends on the other for its existence.
Real-World Problem
Imagine a College Management System. Each Department has multiple Teachers. If a department is closed, the teachers do not disappear. They can be transferred to another department or continue working elsewhere. This means the Department contains Teacher objects, but it does not own their lifecycle. This relationship is called Aggregation.
What is Aggregation? Aggregation is a special type of Association where one class contains another class as part of a HAS-A relationship. In Aggregation, the contained object can exist independently of the container object. It represents weak ownership
Diagram Explanation This diagram illustrates Aggregation using a Department and a Teacher.
- A Department has one or more Teacher objects (HAS-A relationship).
- The Department and Teacher are associated, but the Department does not own the Teacher.
- If the Department is closed or removed, the Teacher continues to exist.
- The Teacher can be assigned to another Department.
- Since the lifecycle of the Teacher is independent of the Department, this relationship is called Aggregation.
Key Point: Aggregation represents a HAS-A relationship with weak ownership, where the contained object can exist independently.
Key Characteristics
- HAS-A relationship.

- Weak ownership.
- Objects have independent lifecycles.
- The contained object can exist without the container.

A "has-a" whole/part relationship where parts can outlive the whole (weak ownership).
import java.util.List;
class Player {
String name;
Player(String name) { this.name = name; }
}
class Team {
private List<Player> players; // Team HAS players...
Team(List<Player> players) {
this.players = players; // ...but players exist independently of the team
}
}
// Deleting the Team does not destroy the Players — they were passed in from outside.