Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to model python properties in UML diagram

What is a good practice to model Python properties in a UML class diagram? Properties themselves are class objects, their getter and setter are class functions. From Outside the class they look like instance attributes. So, how would you suggest to present that in my class diagram?

like image 616
Robert_Jordan Avatar asked Oct 18 '22 13:10

Robert_Jordan


2 Answers

I recommend you read UML Best Practice: Attribute or Association, by another Stack Overflow user named Geert Bellekens. It states simply:

Use Associations for Classes and Attributes for DataTypes.

You should write the Python attributes that are typed by non-datatypes (which have identity) at the ends of UML associations connecting to those UML classes. You should write the Python attributes typed by simple datatypes (which have no identity other than their value) in the UML class' attribute box.

The accessors and mutators are largely just noise. A model compiler or IDE can generate those for you.

like image 99
Jim L. Avatar answered Oct 21 '22 06:10

Jim L.


Good practice is what works on your project.

In order to model Python properties you can add stereotyped getter and setter operations which indicate their use. The link between attribute and operation is usually done via a naming convention. Some tools offer internal linkage to make attributes properties with getters and setters.

If you are not using code generation you can also stereotype the attribute to indicate their use as properties (thus telling the coder to use @property) and leave away the operations. If you are using your own code generator this would work analogously. Tool embedded code generators might need the additional operations as described above.

like image 40
qwerty_so Avatar answered Oct 21 '22 07:10

qwerty_so