UML ternary association
Asked Answered
B

4

14

I'm currently having some trouble understanding ternary associations in UML. I get the binary ones, but I am unsure how multiplicity works on ternary. I'm doing exercises that I got from my university, the current one goes like this:

One department may sell many products, but only to one market. On a market one product may only be sold by one department.

enter image description here

I've read on different sources about how I'm supposed to think about a pair of the two classes I'm not trying to figure out the multiplicity for, but my brain just isn't getting it. Help me Overflow Kenobi, you're my only hope.

Breastbeating answered 24/10, 2017 at 18:19 Comment(0)
S
11

There seems to be some ambiguity in the specification of multiplicities on ternary associations. See also this paper

But I understand it like this:

The multiplicity says something about how many times an instance may be present in this associations for any given tuple of linked instances.

As an example, consider the following (traditional) family enter image description here
I would understand that as

In any given family there must be one father, one mother and zero or more children.

If we apply that to your case then I come to something like this:

enter image description here
I understand that as

For any given Offering there must be exactly one market, one department and one or more products

That seems to satisfy more or less all of your constraints

  • A Product can only be offered to one market by one department
  • A Department can offer multiple products, but one product can only be offered to one market

I don't think it's waterproof though, but as the paper already stated, UML does not have enough tools to make a waterproof design with the multiplicities on the ends alone. So for good measure, your constraints should also be modeled as UML constraints.

Disclaimer: Ternary associations are really nice for academical discussions, but are not really used in the (IT) industry, probably because they are so hard to understand.

Sonatina answered 25/10, 2017 at 6:49 Comment(11)
Great @Bellekens, I presume that at the end, in code, only binaries associations are implemented ...Salliesallow
@Salliesallow not necessarily. I think the implementation in "code" is more common than the use in UML. Think of a struct with fields Market, Department, list<Product>, or a "link" table with FK's to Product, Market and Department.Sonatina
@Bellekens yes you will have a struct/object managing a list of others thinghs with "business rules", and this more near an association class or an object managing a list of binaries associations ...Salliesallow
@Geert Bellekens: There is no ambiguity in the definition of multiplicities for n-ary associations, but they are just harder to understand. Notice that your association name "Family" in your example above is not a good choice since neither the ternary association, nor any of the triples instantiating it, represent a family.Seasickness
@GeertBellekens, For question softwareengineering.stackexchange.com/questions/391341/… , I have consulted the UML 2.5 spec and I think the n-ary association is well specified nowadays. If you have time, please read my answer over there. I think Gerd Wagner's answer below is correct.Afroamerican
@GerdWagner Could you please provide a name for the association which is better than "family"? Also, why doesn't any triple instatiating it represent a family?Publea
@Max: There are many cases of associations that do not have natural names, but do often have natural role names (for association ends). An association is a classifier, and "Xyz" is a good name for a classifier if an instance of it is an xyz, like "Child" is a good name for the lower class since an instance of it is a child. In the case of the "Family" association above, we cannot say that an instance of the association, which is a father-mother-child triple, is a family, because the family may have more children.Seasickness
The entire "Family" association example is conceptually flawed. It allows fathers and mothers not having any children, and it does neither allow a child to be a father or mother, nor a father or mother to be a child!Seasickness
@Gerd Wagner How can we then change the diagram such that the association represents a family? (Or maybe an "instance" should not be considered a triple of three simple objects, but rather a triple of two objects (mother and father) and a set for the children?)Publea
@Max: UML does not support the possibility that a set of objects participates in an association.In general, a familiy is a collection of people that are associated with each other in various ways (e.g., all children having at least one family member as their parent), but there is no natural way to model a family as an association. Only for specific cardinalities, a family could be modeled as an association. E.g., a two-kids-mother-father family could be modeled as an association.Seasickness
"UML does not support the possibility that a set of objects participates in an association" But is this really true? Why would it? This doesn't even make sense for binary one-to-many associations, let alone binary many-to-many associations. This would only make sense if UML class diagrams where limited to one-to-one relations like predicate calculus.Publea
L
6

This unspecific ternary association just tells that you have relations where

  • Market controls Department-Product,
  • Department controls Market-Product and
  • Product controls Department-Market.

There is no statement as to how the single classes control the other two.

The UML specs is not defining the ternary operator in detail. So using that element seems to be on your own risk. You could blame OMG for using but not defining it more than

Any Association may be drawn as a diamond (larger than a terminator on a line) with a solid line for each Association memberEnd connecting the diamond to the Classifier that is the end’s type. An Association with more than two ends can only be drawn this way.

and a single example in a picture on p. 202.

The simple association class

enter image description here

tells you that the Product is in between Department and Market where the multiplicity 1 tells that there's only one Market for a Department. That's more what your requirement sounds like.

N.B. It does not make much sense to split hairs regarding the requirements, so as "is there a Product without a Market". Those are details which need to be discussed with domain specialists before being fixed in a model.

Leadin answered 24/10, 2017 at 21:29 Comment(0)
S
4

The model in the answer of Geert Bellekens is correct, but his explananation is confusing. The ternary association "Offering" with its multiplicities (cardinality constraints) cannot be explained by the statement

For any given Offering there must be exactly one market, one department and one or more products

but rather by stating that

  • a combination of department and product is linked to exactly one market
  • a combination of market and product is linked to exactly one department
  • Seasickness answered 27/10, 2017 at 11:47 Comment(0)
    W
    0

    Ternary and higher association should be modeled conform the ISO standaard where owning ends are reversed in the notation. So for binary association, use the normal meaning of owning ends.

    An intelligent tool should switch parsing mode if encountering a ternary or higher association.

    It has been proved you can split a N-ary association into a lot of binary associations, so we avoid these N-ary usually.

    Wilderness answered 2/11, 2019 at 10:32 Comment(0)

    © 2022 - 2025 — McMap. All rights reserved.