UML class diagram: is this how to write abstract method and property?
-
04-07-2021 - |
Pregunta
When I was creating the first time an uml class diagram for a small C# project I had some trouble with the properties. At the end I just added the properties as a variable with <<property>>
at the start. Now Im wondering how do I solve this with an abstract method? Should I just add <<abstract>>
to the method an fine? Im doing something like this:
-----------------------------------
| <<abstract>> |
| MyClass |
-----------------------------------
|<<property>> + a : int |
|<<property>> + b : string |
-----------------------------------
|<<abstract>> # Job() : void |
|<<abstract>> # Job2() : string |
|- SomeNonAbstractMethod() : void |
-----------------------------------
Is this alright? Any suggestions?
Solución
Every "attribute" is actually a Property in UML2. Abstract methods are displayed by italic text (UML has a boolean value for this).
The notation you are using is called Keyword (simple way) or Stereotype (more complex). If you want to mark a Property as some kind of "special" that's fine with a keyword like you did.
Otros consejos
As there are no properties in UML I think this is a possible solution to emphasize that an attribute shall be implemented as property. However you should document the usage of this non-standard keyword within the document you use the diagram.
Another solution would be to create a convention that all public attributes must be implemented as properties (unless some exceptions occur ... ).
If I remember correctly abstract methods are displayed by using italic text. I do not like this approach though, because it might be overseen more easily than in your diagram. It also might depend on the possibilities your UML editor offers, where I usually prefer to adapt the method of the editor to keep in line with other diagrams drawn with the same editor.