Association and aggregation topic

What is Association ?What is Aggregation ? What are the differences between them ?


1 Answer
1-1 of  1
1 Answer
  • Association is a simple structural connection or channel between classes and is a relationship where all objects have their own lifecycle and there is no owner.
    Aggregation is a specialize form of Association where all object have their own lifecycle but there is a ownership like parent and child. Child object can not belong to another parent object at the same time.
    Different between Assocation and aggregation-
    ​Association is a relationship where all objects have their own lifecycle and there is no owner.
    Let's take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers, but there is no ownership between the objects and both have their own lifecycle. Both can be created and deleted independently.
    Aggregation is a specialised form of Association where all objects have their own lifecycle, but there is ownership and child objects can not belong to another parent object.
    Let's take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department, the teacher object will not be destroyed. We can think about it as a “has-a” relationship.

Object Oriented Programming

Didn't get the answer.
Contact people of Talent-Object Oriented Programming directly by clicking here