haskellumlassociationsclass-diagrammultiplicity

Precise semantic of annotated associations with { bag } and multiplicity bound constraints


Suppose I have A ---r1 {bag} [1..2]--> B in a UML class diagram (that is, r1 is an association from A to B and is annotated with {bag} and multiplicity [1..2].

My Question: if a:A is an instance of A, is the following collection valid?

a.r1={(b1,1),(b1,2),(b2,1)} //collection contains two copies of b1 and one b2

In other words, multiplicity bounds (i.e., [1..2]) apply to the association when it is interpreted purely as r1:A --> B, or it applies to r1: A --> Bag(B)? In the former interpretation, the above collection is valid, since r1 contains at most two instances of B, but in the latter it is not, since r1 contains three elements of Bag(B)! which interpretation is correct?

Multiplicity constraints in UML are explained in Chapter 7.5.3 of UML document as I am referred to in this question.

p.s.1: A similar question arises when we substitute {bag} with {seq}.

p.s.2: I added haskell tag to get comment from large haskell community here as @xmojmr suggested. Thanks to @peter that nicely draw the pictures in his answer.


Solution

  • As stated in specs, Bag is unordered, nonunique collection. However this describes the relation between the elements you are pointing to.

    So your example can be expressed in either way: not the bees

    This means that A has reference to one to two B instances, and those references are stored in a Bag (or any nonunique, unsorted collection; but that is implementation detail).

    To answer your question: no, because the Bag contains three instances of B, whilst the allowed maximum is two B's.