Search code examples
umlassociationsclass-diagrammultiplicity

Showing multiplicity between subclasses of an inheritance and another class out of inheritance


Consider the following class diagram.enter image description here

I need to satisfy two conditions in my model:

1-Node can only have 1 cutted Line, but it can have 0 or many Line instances.

2- A node comes from either a cutted Line, or a Line (but not both)

I first, draw the bellow domain model. But then i made my mind to reduce the complexity by an inheritance of Edge.enter image description here

It seems that the first solution covers the second requirement, but it does not cover the multiplicity. Unfortunately the second solution covers the multiplicity but not the second condition. How can I draw it to satisfy both conditions? Update: I finally, come up with this solution: enter image description here

But i am not sure if it is true or not?


Solution

  • That situation is called a derived union.

    A Node comes from either a CuttedLine, or a Line (but not both)

    The association between Line and Node (or CuttedLine) subsets the association between Edge and Node, because if a Node comes from a Line (or CuttedLine) then:

    • it comes from an Edge
    • that Edge is of type Line (or CuttedLine)

    Moreover, the association between Edge and Node is derived from the associations between Line and Node and between CuttedLine and Node, because if a Node comes from an Edge, then it comes from a CuttedLine or comes from a Line. UML defines a derived union as "as the union of all of the Properties that are constrained to subset it."

    Since a Node comes from a single Edge (the cardinality is 1) and the generalization is disjoint, it follows that a Node comes either from a Line or a CuttedLine, but not both. (The union of two distinct sets has a single element if one of the sets is empty and the other has a single element.)

    Diagram