14

How would I display the field

private static final int DAMAGE = 3;

in the UML Diagram?

Should it be shown as: - DAMAGE : 3 : int ?

2 Answers 2

18

You show it like this.

enter image description here

Private is symbolized by a minus. The static attribute is shown by an underline. The initial value is shown by = <value>. Since I learned that final denotes a constant, you will apply the isConst property which is shown as {readOnly}.

See also p. 111 of the UML spec:

<property> ::= [<visibility>] [‘/’] <name> [‘:’ <prop-type>] [‘[‘ <multiplicity-range> ‘]’] [‘=’ <default>] [‘{‘ <prop-modifier > [‘,’ <prop-modifier >]* ’}’]

[ details omitted ]


No longer relevant in this context, but leaving it anyway:

Re. @granier's comment about tagged values: Indeed UML 2.5 does no longer really use tagged values. There are only 3 mentions of it:

  • mainly p. 205

    Just like a Class, a Stereotype may have Properties, which have traditionally been referred to as Tag Definitions. When a Stereotype is applied to a model element, the values of the Properties have traditionally been referred to as tagged values.

So tagged value is an "ancient" term and should further be called stereotype property.

16
  • 2
    @Kilian, tagged value still exists ? I thought it was used in previous version of the specification, and that now it is stereotype properties. Another point, EA allows to create stereotype easily but I guess that to you use a stereotype you have to define a profile including this stereotype then to load the profile in the project.
    – granier
    Commented Dec 1, 2017 at 9:18
  • @granier You have a point here, I was not aware of. I'll amend my answer.
    – qwerty_so
    Commented Dec 1, 2017 at 10:36
  • I stil think that you can invent stereotypes at wish (like there is no rule for naming classes). It's a meta-classification. But then again, the spec says there must be a profile for a stereotype p. 278 /profile : Profile [1..1]{}
    – qwerty_so
    Commented Dec 1, 2017 at 10:49
  • @granier I started a discussion: sparxsystems.com/forums/smf/index.php/…
    – qwerty_so
    Commented Dec 1, 2017 at 10:53
  • @Kilian, my goal is not to get point but to improve the answer when it make sense ;) . There are "a lot's" of points where EA does not follow the norm exactly ... For example, Modifier cited for the answer about pure virtual ...
    – granier
    Commented Dec 1, 2017 at 10:57
7

For an UML representation of a Java project, it should be sufficient to write underlined caps, like…

A constant in a UML class diagram

Note that this representation uses a Java convention (constants written in capitals) to highlight it as final instead of a UML annotation, which would be kind of more straight-forward UML, but is too long for my purposes.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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