1

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

1

You are going in the right direction with the 3 subclasses. Let's combine that with derived attributes and redefines method to get desired effect.

If the property is derived, its value can be calculated from other attributes (including the information which specific subclass are we in. This is not directly mentioned in the UML Specification but comes as a logical consequence).

If the property in child redefines property from parent it usually specifies it in more details. One of obvious possible redefinitions is the change of attribute data type. In this case the change will be from broader (complete) enum to a narrower one.

Since all subclasses have to have all the attributes, keep them in the parent class Class1 (which by the way should be abstract)

Now the values for attributes EnumType and AttributeValue depend strictly on the subclass chosen, so it means these are derived attributes. Also since it cannot change within the subclass, you can set it on the subclasses to ReadOnly and provide the default value effectively enforcing this specific value.

For DataType you have 3 enumerators, one (DataTypes) with the broadest list and two that are specialised versions of DataTypes, each narrowing the list further (respectively DataTypesList and DataTypesNone). You may want to show this specialisation with respective generalization relationship.

The type of attribute DataType for ClassDiction remains the broadest version, so you do not need to change anything there. On the other two child classes you redefine the DataType with the narrower enumeration.

Note, new versions of EnumType and AttributeValue also redefine their original versions from Parent class adding constrains and defaults, thus also require proper redefines.

As a result you get the following diagram:

enter image description here

Note that while this diagram accurately depicts what you have described, it's using a bit more advanced UML. Always consider who is going to read the diagram. Sometimes it's better to add just some textual description (either supplementary or as a text annotation/constraint) rather than depict accurately to ensure that all recipients will understand the message.

  • thanks for your hints, I try to use them. Question: shouldn't the enumarations be connected vice versa? Usually specialization of classes comes with more attributes. I see that DataTypes is most general in meaning of "all". 2nd Question: an abstract Class1 would deny any instantiation thus implying usage of the 3 others? 3rd Question: why redefining e.g. EnumType and not just default value combined with readOnly (for AttributeValue I can "map" you explanation)? – Shegit Brahm Feb 11 at 11:43
  • @ShegitBrahm you're right. According to specification the arrows are in the opposite direction. I'll fix that when I will be able to access the model. – Ister Feb 11 at 19:23
  • I came across confusion, so updated example. I still lack understand of refine-needs beyond DataType (I see here: change of enum), because I think I just need to set the value. And ... how to handle that DictCollection definition? Do I need an extra attribute to get the real values of "Value" stored? See dropbox.com/s/u7hyybxi2vjjtzc/… for further attempts. – Shegit Brahm Feb 14 at 14:35
1

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.

  • 1
    true, I talked to so. else and he pointed out that I falled for the inner platform effect and that a class definition has to be "finally modeled" at design time, not executing time. I realized it then and decided to "thing again when I have to have time for it" and post then an update. – Shegit Brahm Mar 16 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.