Objects(Class) Relationship, Aggregation/Composition vs Generalization
Author: Mohammad J Iqbal
In Object Oriented Design it is very important to understand the class relationships after you discover the classes you might require to complete your design. Two very important relationships are “is a” and “has a” relationship.
#Association: Represents a bi-directional relationship between two classes.
Example: Each Library contain multiple books and each book belongs to a library.
#Directed Association: Represents a relationship between two classes where the association has a direction.
Example: In a “University System” Teacher takes course.
#Aggregation: Whole-part relationship where part can exist without whole
Example: Data Center and Server, where Server is not strongly associated with Data Center and can exist without Data Center.
#Composition: Whole-part relationship where part can not exist without whole.
Example: House and room. If you demolish a house, there will be no existent of rooms.
Both Aggregation and Composition represents “has a” relationship where Inheritance or Generalization represents “is a” relationship.