UML Class Diagrams – Modeling Attribute Dependency Within a Class

class-diagramdependenciesuml

I have the following "software reality in working code" (also no access to it):

  • There is a class Class1 with different attributes
    • AttributeA – sums up all "ordinary attributes"
    • EnumType
    • DataType
    • AttributeValue

It is realized that there are some objects John… of type Class1, so they all have these 4 attributes. They can be set via GUI. The tricky part is: First EnumType has to be chosen. Depending on this choice the possible choices for DataType might be reduced. And the "attribute type" of AttributeValue might differ:

  • EnumType = None => DataType: int | char && AttributeValue: Field
  • EnumType = List => DataType: int | char | double | String && AttributeValue: []-Array
  • EnumType = Diction => DataType: int | char | double | String | XML && AttributeValue: DictCollection

[update 2019-02-14]:

  • Shortened AttributeValue to Value.
  • ValueType 'String' switched to 'Field' for less confusion.
  • Changed from [][]-Array to DictCollection to make clear it is a collection of key-value-pairs where the type for all keys is the same chosen from DataType, while the one for value might be a different from DataType [/update]

Example: in case of Diction it is possible to have many entries, each entry consisting of two fields with (each independently) entries in the possible data types int | char | double | String | XML. First field could be XML, second could be double.

[update 2019-02-14]

e.g. JohnA: None=>Field | => char ='a' | AttributeA
JohnB: None=>Field | => int = 23 | AttributeA
JohnC: List=>[]Array | => String =["hello","world","list"] | ...
JohnD: Diction=>DictCollection | => {XML, double} = {(<length>, 2.34); (<width>, 5.43)} | ...

[image updated 2019-14-02]
Tried to show it that way: class diagram with example values

My question: how to model Class1 in UML?

My research reading:

I tried to adopt it to my case. Either it is not mentioned or I don't understand it. It sounded like the derived property is what I'm looking for … just it is not a simple concatenation or calculation. Does it still takes effect?

Additional info: this Class1 also needs to be used in another class as data type of attributes over there as well – just in case that is relevant to ensure that while using it as data type the class structure and inner dependencies are coming into affect.

I tried this approach:

  • top row is "plain" without any dependies, my "blank page to start from"
  • Class1 with all common attributes AttributeA
  • Specialization regarding EnumType
  • three enumerations for DataType and visually linking them (to sort my brain, I know that in final draft there is none)

This approach has some issues:

  • EnumType is only set to default and not "fixated", there is no dependecy that this subclass request this setting
  • AttributeValue the same
  • there are multiple enumerations with overlapping content

[image updated 2019-02-14]

modeling start and attempt

Best Answer

UML is built on a layered basis, where the MOF defines the classifiers in the UML metamodel and your UML model is an instance of the classifiers in the UML metamodel and your objects are instances of the classifiers in your UML model.

Your 'EnumType' is acting as a type in the same layer as the instance it is controlling; this crossing of layers is not directly supported in UML. If you want to represent it, you need to work in a different formalisation, where types and instances can co-exist in the same model.

This does not prevent you creating informal work-arounds, such as using extensive rather than intensive classifiers as Ister gives examples of.