-2

If I understand correctly composition and aggregation are relationships that objects share. In composition, the dependent object cannot exist without the parent. Whereas, in aggregation, the dependent objects can exists without a parent. The composition is implemented in java by having non-static inner class but aggregation by having a static inner class or object references. Please correct me if I am wrong. Have browsed through web lot but didn't get satisfying answeres just confusion.

1 Answers1

0

First of all both Composition and Aggregation are part association. Association means relation exist between classes.

In Composition which two entities are highly dependent on each other and the composed object cannot exist without the other entity.

class Employee{

}

class Company{
List<Employee> employeeList;
}

Aggregation:

It is a unidirectional association ( one way relationship) Both the entries can survive individually which means ending one entity will not effect the other entity

//Either girl like boy
class Girl{
 List<Boy> boyList;
}

//Either boy like like
class Boy{
 List<Girl> girlList;
}

I'm giving this example because i'm a programmer, you also know that.

Abid Khan
  • 11
  • 3