Search code examples
umlcompositionclass-diagram

Multiple compositions in UML


In a UML class diagram, is it technically correct to have two possible compistion relationships leading to one class?

I.E. I have an inventory class, which has a composition of the inventory class. I want to have the same relationship but with a container class taking the place of the inventory.

So, can I have two compositions, or do I need to turn these into aggregations?


Solution

  • You can have as many composite associations as you like on the class level. But each instance can only be part of one composition at a specific moment in time. UML superstructure says:

    If the whole has aggregationKind = composite then the part can be included in at most one composite at a time

    This article I wrote tries to explain the difference: UML Composition vs Aggregation vs Association