如何在 UML 中表示 C# 属性? [英] How to represent a C# property in UML?
问题描述
不完全是一个属性,也不完全是一个方法.刻板印象?<<
<<
?
Not quite an Attribute, not quite a Method. Stereotypes? <<get>>
<<set>>
?
我正在对现有系统进行复古建模,因此我需要清楚地反映这与只读字段或方法对不同(无论 IL 怎么说),所以我想我'将采用刻板印象,但我将接受与语言无关的 get_set_ 作为通用解决方案.感谢大家的理智测试.
推荐答案
Properties 只是一种方便的书写方式 get_MyValue()
和 set_MyValue(value)
允许赋值而不是比普通的方法调用(使用括号).
Properties are just a convenient way of writing get_MyValue()
and set_MyValue(value)
allowing assignment rather than the normal method calling (using parenthesis).
您正在访问的实际上是一个 .NET 属性,C# 有自己的语法来访问这些属性.由于在皮肤下创建了真正的 get_
和 set_
方法,因此您可以简单地显示这些方法(以使您的 UML 语言独立 - 例如使您的 UML 同样适用于VB.NET 开发人员)
What you are accessing is actually a .NET property, C# has its own syntax for accessing these. Since under the skin the real get_
and set_
methods are created, so you could simply show those methods (to make your UML language independent - e.g. make your UML equally applicable to a VB.NET developer)
...或者按照您的建议,介绍您自己的刻板印象!
... or as you have suggested, introduce your own stereotype!
这篇关于如何在 UML 中表示 C# 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!