What type of composition would this be?

66 views Asked by At

I have a question regarding on how can I make a diagram by using my code.

I have a class Player and inside of this class there are some methods. I have another class called HealthManager which decides how much health would the player have.

In my Playerclass I'm using a HealthManager object to make some decisions (like dropping health to 0) and in my HealthManager class I'm using a PlayerClass object for some stats.

Can I call this type of relation an Association ?

2

There are 2 answers

0
www.admiraalit.nl On

Yes, you can call it a 1:1 association.

0
Ister On

It's a question if the HealthManager is a part of Player and it seems so according to your description (and comments).

This means you have here a whole-part relationship, moreover HealthManager is assigned to exactly one Player which means it's a composite aggregation (composition). The fact that HealthManager can retrieve some information from the Player shows only that this composition has also backward navigability (i.e. from HealthManager to Player) which is absolutely fine (and is depicted with an open arrow just before the filled diamond).

If the HealthManager is destroyed when it's Player is destroyed then you're almost sure that it's a composition.

Consider also that both shared and composite aggregations are specialisations of association i.e. they are also associations. Having this said if you just document a 1:1 association instead of composition it's still correct, just don't give some details about your model.