Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I add a final variable to class diagram

I am designing a class diagram for scrabble game. In one of the classes, I have final variable declared. Can anybody tell me, how can I indicate a variable as final in the UML class diagram?

like image 518
Noopur Phalak Avatar asked Apr 27 '13 12:04

Noopur Phalak


1 Answers

There are different notions of final that are all represented in different ways:

  • final definition, i.e. it cannot be overridden in sub-classes - this corresponds to the isLeaf property of the attribute:

    The isLeaf property, when true for a particular RedefinableElement, specifies that it shall have no redefinitions.
    - UML 2.5 specifications, page 99

    There is no official notation anymore for attributes with isLeaf=true; adding {leaf} was the former official notation (UML 1.x) and it is still common.

  • final value, i.e. its value cannot be changed - this corresponds to the isReadOnly property of the attribute:

    If a StructuralFeature is marked with isReadOnly true, then it may not be updated once it has been assigned an initial value. Conversely, when isReadOnly is false (the default), the value may be modified.
    - UML 2.5 specifications, page 106

    Notation for read-only attributes consists of appending {readOnly} to the attribute string.

  • constant usually refers to a non-changeable attribute of the class itself instead of an instance (static final attribute). In UML it would have both properties mentioned above and additionally be static, which corresponds to the isStatic property:

    The isStatic property specifies whether the characteristic relates to the Classifier’s instances considered individually (isStatic=false), or to the Classifier itself (isStatic=true).
    - UML 2.5 specifications, page 105

    Static attributes are indicated by underlining the attribute definition. Constants, as already mentioned are usually UPPERCASE, but that's just a convention.

So, to sum it up, a constant attribute FOO of type String with value "x" would look like this and be underlined in addition (which isn't supported here):

+ FOO : String = "x" {readOnly,leaf}
like image 199
Carsten Avatar answered Oct 16 '22 13:10

Carsten