12

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 :)

nipeco
  • 760
  • 2
  • 9
  • 24

1 Answers1

15

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

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • 6
    This could be an oportunity, i have now found a better solution. UML 2.0 says you can add properties like this {readOnly} to each attribute. – nipeco Jan 26 '17 at 10:36
  • 1
    You are right. I missed that paragraph. Will make an update to my answer. – qwerty_so Jan 26 '17 at 11:51
  • The second example is nice because it also illustrates a derived field (area) which uses the / access operator -- it is natural that such a field would be read-only! – Josiah Yoder Dec 18 '19 at 17:21