Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

uml - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...