Representing a C# accessor property in a UML Class Diagram?

有些话、适合烂在心里 提交于 2020-01-04 05:39:16

问题


How does one represent a C# property (setter and getter accessors) in a UML Class diagram?

Do you just write it as regular setter and getter methods?

Or is there some other way of representing it?

I'm interested in how accessors are represented in a class and interface in a UML Class diagram.


回答1:


Some developers / analysts:

(1) show properties as a very conceptual thing, and only show a single row per property.

(2) Others, are more specific, and display 3 rows, the property, the "getter" function, the "setter" function.

(3) And sometimes, only show 2, for the accesors.

(4) Some U.M.L. drawing apps. allows you to select which of the prior, do you want to display.

And...

...As far as I have investigated, all options are right. Remember, that stereotypes ("<<some stuff>>", are allowed to help document the class.

(Note: I replace spaces by dots)

(1) Only plain property (C#, very conceptual):

+================================================================+
|..........................MyClass...............................|
+----------------------------------------------------------------+
|..[+]..|..void....|..MyClass()...|..<<constructor>>.............|
|..[+]..|..void....|..~MyClass()..|..<<destructor>>..............|
+================================================================+
|..[+]..|..string..|..Text........|..<<property>>................|
+================================================================+

(2) Only "accesors", (C++, Java, style):

+================================================================+
|..........................MyClass...............................|
+----------------------------------------------------------------+
|..[+]..|..void....|..MyClass()...|..<<constructor>>.............|
|..[+]..|..void....|..~MyClass()..|..<<destructor>>..............|
+================================================================+
|..[#]..|..string..|..FText.......|..<<field>>...................|
+================================================================+
|..[+]..|..string..|..getText()...|..<<function>>,..<<getter>>...|
+----------------------------------------------------------------+
|..[+]..|..string..|..setText()...|..<<procedure>>,..<<setter>>..|
+================================================================+

(2) Everything (Very Programmer, Object Pascal / Delphi style):

+================================================================+
|..........................MyClass...............................|
+----------------------------------------------------------------+
|..[+]..|..void....|..MyClass()...|..<<constructor>>.............|
|..[+]..|..void....|..~MyClass()..|..<<destructor>>..............|
+================================================================+
|..[#]..|..string..|..FText.......|..<<field>>...................|
+================================================================+
|..[+]..|..string..|..Text........|..<<property>>................|
+----------------------------------------------------------------+
|..[+]..|..string..|..getText()...|..<<function>>,..<<getter>>...|
+----------------------------------------------------------------+
|..[+]..|..string..|..setText()...|..<<procedure>>,..<<setter>>..|
+================================================================+

Are you delivering to analysts ? Does your C++ / Java programmers know that if the diagram shows only properties, they have to code the acccesors, or your company requires to explicity declared them in the diagrams ?

Choose the one that fits more your needs. (remove dots).




回答2:


I don't think you really need to worry about how to represent language-specific conventions in a UML diagram. After all, that is an implementation concern, not a design concern. I'd recommend representing your accessor methods as you would in any other UML diagram and then work out the implementation of your design when you get to that point in the project and not one minute sooner.

Sorry, I realize this is not really a direct answer to your question, but it is good practice nonetheless.




回答3:


It should be set as an attribute. If it only has a getter, set it to readonly. There is no specific UML for C# properties.



来源:https://stackoverflow.com/questions/5432591/representing-a-c-sharp-accessor-property-in-a-uml-class-diagram

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