How to model python properties in a UML diagram

What is the good practice of modeling python properties in a UML class diagram? Properties themselves are class objects; their getter and setter are class functions. Because of the class, they look like instance attributes. So, how would you suggest presenting this in my class diagram? Thanks

+5
source share
3 answers

I recommend that you read UML Best Practice: Attribute or Association by another user named Geert Bellekens . He just says:

Use associations for classes and attributes for data types.

You must write Python attributes that are typed by non-datatypes (which have an identity) at the ends of the UML associations associated with these UML classes. You must write the Python attributes typed by simple data types (which do not have an identifier other than their value) in the attribute field of the UML class.

Accessors and mutators are basically just noise. A model compiler or IDE can generate them for you.

+2
source

Good practice is what works on your project.

To model Python properties, you can add stereotypical operations with getters and setters that indicate their use. The relationship between an attribute and an operation is usually done using a naming convention. Some tools offer internal communication for creating attribute properties using getters and setters.

If you do not use code generation, you can also stereotype an attribute to indicate their use as properties (thus, using @property talking encoder) and to get away from operations. If you use your own code generator, this will work in a similar way. Instrumental embedded code generators may require additional operations, as described above.

+1
source

Actually, it depends on which template your UML tool uses. Some tools have a Properties field along the common Attributes and Methods fields. The UML designation says that the attributes are written on the lower disk, you can write the properties at the top of the camel. They will also differ visually due to the public access modifier (+).

Do you need to specify different access modifiers for getter and setter? I am not sure how I will go about this. Keep in mind the required level of abstraction.

Remember that UML is basically a set of defined standards. If the standard needs a little customization to fit your needs, feel free to. The important thing is that your team and stakeholders understand the syntax.

0
source

Source: https://habr.com/ru/post/1245622/


All Articles