简体   繁体   English

C#UML类图

[英]C# UML Class diagram

I'm writing a class diagram for my project, but unsure whether or not I should be including my overridden ToString() method on the diagram? 我正在为我的项目编写一个类图,但是不确定是否应该在该图上包含重写的ToString()方法吗?

Also, how do I represent overridden methods on the diagram? 另外,如何在图表上表示重写的方法?

For example... 例如...

public override String SalesPrice()

okay so I finally found the book I mentioned (I am moving soon so it was packed). 好的,所以我终于找到了我提到的书(我很快就要搬走了,所以已经装箱了)。

in UML Inheritance is called generalization and it simply shows 2 boxes one pointing to the other no attributes. 在UML中,继承称为一般化,它只显示2个框,一个指向另一个无属性。

I would assume that since you have defined the method in a base class that you would not have to in classes that inherit from it. 我假设由于您已经在基类中定义了该方法,因此您不必在从其继承的类中进行定义。

however there is a place that states that operations are defined as: 但是,有一个地方指出操作定义为:

" visibility name ( parameters ) : return-type { properties }" 可见性名称( 参数 ): 返回类型 { 属性 }”

and for properties: 对于属性:

" properties 属性

Specifies any parameters-related properties and is specified between curly braces. 指定任何与参数相关的属性,并在花括号之间指定。 These are typically defined within the context of a specific model" 这些通常是在特定模型的上下文中定义的”

although the properties seem more for the parameters than the actual method but you may be able to fudge this a little 尽管参数的属性似乎比实际方法更多,但是您可能可以对此稍加修饰

now for interfaces: 现在用于接口:

under the interfaces section it states explicitly that the class that "realizes" the interface must have it's own implementation. 在接口部分下,它明确指出“实现”接口的类必须具有自己的实现。 so in short I would add any overridden methods to the class diagram. 简而言之,我将在类图中添加任何覆盖的方法。 otherwise whom ever implements your diagram might not realize that they need to override it. 否则,曾经实现您的图的人可能不会意识到他们需要覆盖它。

I am using uml 2.0 in a nut shell as my reference. 在坚果壳中使用uml 2.0作为参考。 pg's 20,28,30 pg的20,28,30

Usually you wouldn't really need to include any extra details on the UML class diagram that the method is 'Overriden' or 'Virtual' Etc, 通常,您实际上不需要在UML类图上包含方法为“覆盖”或“虚拟”等的任何其他细节,

But if you wish to do so, I was told that it should be represented in the same way as abstract classes (Italic writting) / use of 'Arrows' either side like so.. 但是,如果您希望这样做,我被告知应该以与抽象类(斜体写法)相同的方式来表示它/像这样在任一侧使用“箭头”。

<<Override>>
<<Virtual>>

So to comply with your example: 因此,为了符合您的示例:

+ SalesPrice (): <<Override>> : String

and within your superclass you will need to specify as follows: 并且在您的超类中,您需要指定以下内容:

+ SalesPrice (): <Virtual>> : String

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM