Handling object relationships within code:
Relation | Handling |
---|---|
Aggregation | References |
Composition | References |
Generalization | Abstraction |
Realization | Interface |
Relations may also be:
Bank and Customers are a good example of one-to-many relationship.
https://www.digitalocean.com/community/conceptual_articles/s-o-l-i-d-the-first-five-principles-of-object-oriented-design
Tightly-Coupled & One-To-One. Both objects have strong dependency on one another.
class School {
private Department d;
School() {
d = new Department(this);
}
// Public getter.
public Department getDepartment() {
return d;
}
}
class Department {
// Keeps reference to that particular School instance.
private School s;
// Take reference.
Department(School school) {
s = school;
}
// Public getter.
public School getSchool() {
return s;
}
}