Search code examples
umlclass-diagram

How to model different variations of similar classes in an UML Class Diagram?


Trying to implement a class diagram and I am not sure how should it done properly. Here is the problem:

Miners can extract gold, silver and coal (the mines are homogeneous, always contains one type). In addition, there are some dangerous mines: e.g some might collapse or be radioactive.

How can I represent this on a class diagram? First, I thought it can be done with one Mines class. From that with generalization I candefine the collapsible and radioactive mines. But I can't decide how to deal with the different material types. Should that be classes too or attributes in the Mines class?


Solution

  • The simpler the better. Without specific behavior in the statement depending on the extracted substance it is enough to have only one class Mine, and the the list of possible substances being known an enumeration is enough. Because a mine produces only one substance the multiplicity is 1.

    The statement doesn't say if the mine can both be radioactive and collapse or not.

    Supposing a mine can both be radioactive and can collapse, you can use an attribute for each danger:

    enter image description here

    It is also possible to use a enumeration for the danger and the multiplicity 0..2 but it is also necessary to have a constraint saying each danger appears at most one time, so this is not a simple way.

    Else if even less probable a mine can have at most one danger you can again use a enumeration with the multiplicity 1:

    enter image description here

    or with the multiplicity 0..1:

    enter image description here