Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composition and Aggregation in a Class diagram

I am having a hard time understanding these when it comes to designing a class diagram, from what I know composition is a "has-a" relationship but Aggregation ?? I have no idea what is it. and one thing when will I know to use Composition in a class diagram? and when will I know to use Aggregation in a class diagram?? a example will be highly appreciated.

like image 295
user962206 Avatar asked Nov 10 '11 09:11

user962206


1 Answers

The main difference between an aggregation and a composition is the property of your "has-a" relationship. It' either strong or weak.

The aggregations "has-a" relationship is of "weak-type". Weak meaning the linked components of the aggregator may survive the aggregations life-cycle or may be accessed in some other way. A simple example would be a football club with its members. If the club is dissolved, you still got the members - which in fact could also be members of other clubs and thus are kept alive.

The composition "has-a" relationship is of "strong-type". Strong meaning that one can't exist without the other. The component's life-cycles are directly linked to the "parent". An example would be a house with rooms. If you decide to tear the house down, you will also lose your rooms.

Maybe a little abstract but I think that's the idea behind it.

like image 102
chrismoe Avatar answered Sep 22 '22 04:09

chrismoe