Reputation: 13
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 |
-------------
I just want to be sure my class diagram is accurate, or at least more meaningful.
Thank you
Upvotes: 1
Views: 1912
Reputation: 36333
Rather than properties use named associations:
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.
Upvotes: 2
Reputation: 6099
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.
Upvotes: 1