1

I can't seem to find this existing question but feel free to point me to it.

Imagine the following situation of a familiar fairy tale:

 ------------            -------------
|    Bear    |--------<>|  BearHouse  |
|------------|          |-------------|
|+name:string|          |+mama: Bear  |
 ------------           |+papa: Bear  |
                        |+baby: Bear  |
                         -------------
  • Is this considered aggregation or composition? (I would assume composition)
  • If composition, does a single black-diamond line suffice, or should I use 3 of them?

I just want to be sure my class diagram is accurate, or at least more meaningful.

Thank you

  • Possible duplicate of [Aggregation vs Composition vs Association vs Direct Association](http://stackoverflow.com/questions/21967841/aggregation-vs-composition-vs-association-vs-direct-association) – qwerty_so Oct 19 '16 at 09:14

2 Answers2

2

Rather than properties use named associations:

enter image description here

Probably a multiplicity of 1 for papa and mama and 0..* for baby would be fine (though in these times there's also possible to have papa or mama as 0..2 and for Mormons mama to be 1..*)

Regarding composition: better you forget this nasty concept. It does not bring real added value and only causes fruitless discussion about its need. Just use associations with multiplicity. Composition/aggregation can be used in certain database design concepts and (what's not really needed today) in memory management concepts.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • Thanks for the sample chart. Can I read that as Bear and BearHouse having a 1:1 relationship, but 3 times? – Daniel Clark Oct 22 '16 at 00:43
  • If you denote multiplicity, it must be per each single association. Alternatively you can add a simple note or constraint. This however is only parsable by humans. Code generators prefer explicit notation. – qwerty_so Oct 22 '16 at 07:30
1

I would assume a BearHouse is not 'composed of' Bears, but only serves as one possible location of Bears. I would use neither aggregation nor composition.

By the way, there is some redundancy in your diagram. The relationship says a BearHouse consists of Bears and the properties mama, papa and baby say that, in addition to that relationship, the BearHouse has a relationship with three Bears in particular.

www.admiraalit.nl
  • 5,768
  • 1
  • 17
  • 32