Home > DeveloperSection > Forums > Aggregation and Composition in java
Royce Roy
Royce Roy

Total Post:149

Posted on    March-17-2015 1:44 AM

 Java Java 

 2 Reply(s)
 761  View(s)
Rate this:
can any one explain the aggregation and composition with the low level example that i can understand easily example should be programming example

Samuel Fernandes
Samuel Fernandes

Total Post:159

Posted on    March-17-2015 1:48 AM

Composition means that the object doesn't make sense without the composed part.
Aggregation means the aggregated part can exist independently from the object. 

Example:  a car doesn't make much sense without an axle and vice versa. So a car is composed of an axle. But the CD player in the car can exists independently from the car (in some cases). So the car and the CD player are aggregated.

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    March-17-2015 1:55 AM

For car example:
Composition: Car and wheel. 
Aggregation: Car and passenger.

This diagram will make the difference more clear among the relationships:

Don't want to miss updates? Please click the below button!

Follow MindStick