umlassociationsclass-diagram

can boolean or enumerative attributes influence the association number?


can a boolean or type attribute influence the number of associations this can have? how could I make it so that if for example the boolean attribute is set to 1 it means that e3 can be associated with e1 only when years of the association class are different, while if it is 0 it means that there can be more associations towards example of when boolean is 1 e3-1300-e1 e3-1300-e1 error boolean is 0 e3-1300-e1 e3-1300-e1

Is this type of reasoning correct? could a solution be to eliminate the main association and create a new one in the subclasses since they are specific for those cases?

enter image description here


Solution

  • Alternative 1: specialization

    Instead of having a boolean (or an enumeration) to control E3's behavior or structure, you could instead specialize E3 into E3-b1 and E3-b2 (... E3-bn if more members in the enumeration).

    These specializations would automatically inherit E3's associations, and in consequence also E2's.

    For the relevant specialization, you can then either

    A few reasons could be against this approach for example your UML tool doesn't support well inheritance between associations, or your implementation language does not allow to change class at run-time an you'd need rutile flexibility.

    Approach 2: contraints

    A simpler approach is to keep your design and add a constraint on the association or on E3. The constraint would limit the maximum number of linked E1 instances based on some predicate involving your boolean/enumeration.

    This can be done in either of the following ways: