Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut for denoting or implying getters and setters in UML class diagrams

In a UML class diagram, if a class has 5 private attributes that need to be mutable and readable, the UML gets pretty ugly with 10 get/set methods even without any of the class' interesting functionality:

Bloated

Ugliness aside, I feel like the UML should focus on the class' more interesting functionality. Am I correct?

Is there some standard shortcut for denoting or implying getters and setters for private attributes?

like image 285
kdbanman Avatar asked Jan 25 '15 18:01

kdbanman


People also ask

Do you put getters and setters in UML class diagram?

For the assignment, we're only expecting you to have a class diagram with attributes and not methods. For UML, it's generally accepted that you don't list getters and setters.

What keywords create getters and setters in classes?

To add getters and setters in the class, use the get and set keywords.

What are the symbols used in the UML class diagram?

Pre-drawn UML class diagram symbols represent class, template class, object, item, package, interface, dependency, composition, and association, etc. These symbols help create accurate diagrams and documentation. UML class diagram templates offer you many useful shapes.


2 Answers

You are correct: there is no need to include the (noise of) "boilerplate" signatures of standard setters and getters in a class model. Unfortunately, UML does not define a standard notation for implying getters and setters for private attributes. So, you'd have to use your own convention. For instance, you could include a general explanation (that all private properties have getters and setters, while private read-only properties have only getters) as a UML Comment, shown as a rectangle with the upper right corner bent (also called a “note symbol”) attached to the diagram.

If you prefer to make the getter/setter convention more explicit for the properties concerned, then create your own stereotypes (e.g., «get/set» and «get») to be used for categorizing these private properties, as shown in the following diagram:

Class with get/set attribute stereotypes

I'm also using this for describing/documenting the implicit getters and setters of ECMAScript 6 classes.

like image 80
Gerd Wagner Avatar answered Sep 19 '22 14:09

Gerd Wagner


UML does not define getter setter operations. Get and Set method are used in programming languages to realize attribute definition. For example, readonly attribute will have getter method only in implementation code. if attribute is defined as calculated, getter method is usually used in code to implement calculation, and setter can be leaved out, because calculated attributes are usually readonly. Visibility of attribute is usually moved to visibility to getter and setter methods in code as well. It does not make sense to define geter and setter methods in code for attributes defined read write and not calculated.

like image 45
Vladimir Avatar answered Sep 17 '22 14:09

Vladimir