user997112
user997112

Reputation: 30655

UML Class diagram object composed of 4 objects of another class?

I have one object, call it type A which has four data members of another object type, call it B. How do I show this in a UML class diagram so that its clear there are four B objects type in every A object?

Is the only solution to put "4" next to the arrow head pointing to class B?

Upvotes: 0

Views: 1059

Answers (4)

Sylvain H.
Sylvain H.

Reputation: 133

From my point of view, myBs defined as an attribute of type B on class A has a different meaning of myBs defined as a association's role between A and B (which is also different as defining it as a composition/aggregation).

If it is an attribute, then it's not a role. In that case, there is only a simple dependency relation between A and B, which must appear in the diagram.

I think that problem comes from unconsciously think from a "Relationnal Data (BMS)" and/or a "Object Oriented Programming" point of view, but UML is not intended for that. :)

Upvotes: 0

Vladimir
Vladimir

Reputation: 2129

You cal also use composite structure diagram. See example below:

enter image description here

Upvotes: 0

Oliver Watkins
Oliver Watkins

Reputation: 13539

Aleks answer is the best. However you can also represent the multiplicity in one box like this :

enter image description here

Upvotes: 0

Aleks
Aleks

Reputation: 5864

It depends on what you want to achive, in sense of how you need to distinguish between those objects in context of their association/link, that is - what kind of role they play:

  • if there are all equal, no special differences in their role in context of A, them a multiplicity 4..4 will do the job, naming the association end properly (for example my_Bs)
  • If these object play different role in connection with A, then you can use separate associations with lower multiplicities each one, 2, 3 or even 4 pieces (for example, if B is a Wheel and A is Car, then you can put 2 associations with multiplicities 2..2 each, and call then "front" and "rear", or even 4 associations "front_left", "front_right"...)

Here is how the both cases look like. On the second one I showd different possible options (with max. 5 elements of B), just to give you an idea.

enter image description here

It's probably clear by now, but the fundamental concept here is the role of the association end.

Upvotes: 2

Related Questions