Search code examples
restmodelumlclass-diagram

How to show attribute as "readonly" in UML?


I want to describe some models of an API in a diagram. Is there a standard how to mark an attribute as readonly? These attributes are set by the system and cannot be modified by the API consumer.

Currently I abuse the class diagram notation for private and public attributes. But I am not satisfied with this.

Thanks for your thoughts :)


Solution

  • The usual way when you interface coding you would make private properties and use getter/setter operations. You could also leave it on a more abstract level and simply stereotype them with <<readonly>> or <<r/o>>. And finally you could use an appropriate getter method.

    enter image description here

    Edit The current UML 2.5 spec states on p. 17

    Attributes: each specified by its name, type, and multiplicity, and any additional properties such as {readOnly}.

    An example on how to use this is found on p. 113:

    enter image description here