UML class diagram: is this how to write abstract method and property?

為{幸葍}努か 提交于 2020-01-03 07:30:13

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12636575/uml-class-diagram-is-this-how-to-write-abstract-method-and-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!