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 ?

Alexander Ivanchenko
  • 25,667
  • 5
  • 22
  • 46
Istiak Khan
  • 173
  • 2
  • 2
  • 10

2 Answers2

17

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.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • 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 Dec 01 '17 at 09:18
  • @granier You have a point here, I was not aware of. I'll amend my answer. – qwerty_so Dec 01 '17 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 Dec 01 '17 at 10:49
  • @granier I started a discussion: http://www.sparxsystems.com/forums/smf/index.php/topic,38955.msg241373.html#msg241373 – qwerty_so Dec 01 '17 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 Dec 01 '17 at 10:57
  • "have a point" means "you have a good/interesting argument", not getting SO-points :-) And thanks for the hint indeed! – qwerty_so Dec 01 '17 at 11:30
  • @granier The Sparx discussion got some feedback and I updated my edit above. – qwerty_so Dec 01 '17 at 18:25
  • @Killian, great and thanks for the information, i do not follow sparx forum. – granier Dec 01 '17 at 19:06
  • @ThomasKilian Assuming "final" in this case is the term java uses to define a constant, you can show that simply by using all caps as you have it, can you not? – BobRodes Dec 02 '17 at 06:19
  • @granier That would be a Java convention then, not an UML one. – qwerty_so Dec 02 '17 at 08:54
  • @Kilian, it was not my remark ... about java caps, i would never do a such remark ... :) – granier Dec 02 '17 at 10:31
  • @granier Oops ;-) – qwerty_so Dec 02 '17 at 11:36
  • @BobRodes See my comment 2 above (addressed wrongly). – qwerty_so Dec 02 '17 at 11:37
  • @ThomasKilian Sorry, my question wasn't at all clear. The use of "final" to mean a constant is a peculiarity of java syntax. However, it is indeed a UML convention to use all caps to denote a constant, although I don't find evidence that it is a universally accepted or official one. That given, might it be said that creating a <> stereotype is unnecessary? Or why not? – BobRodes Dec 02 '17 at 19:24
  • @BobRodes That convention comes from C-times but it is not a UML specification. However, there's a `isConst` property in UML which could be used instead. I'll make an update to the answer. – qwerty_so Dec 02 '17 at 19:26
  • @ThomasKilian Interesting. Yeah, I know that the convention isn't specifically a UML one. Thanks! – BobRodes Dec 02 '17 at 19:27
5

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.

deHaar
  • 17,687
  • 10
  • 38
  • 51
  • 3
    *underline is for static type*, search for static in https://www.uml-diagrams.org/class-reference.html – Sujay Feb 13 '20 at 10:43