Override method in uml

心不动则不痛 提交于 2020-06-15 19:59:50

问题


I am trying to create UML diagram. For example I have a class A with method a() and class B that extends A and overrides method a(). Is there any standard to indicate overridden methods in UML?


回答1:


As indicated in that answer https://stackoverflow.com/a/28932482/2458991 there is a specific indicator to indicate a member (for instance an operation) is inherited, but that indicator is not mandatory, the norm says :

Members that are inherited by a Classifier may be shown on a diagram of that Classifier by prepending a caret ’^’ symbol to the textual representation that would be shown if the member were not inherited.

So, having :

B does not override oper

But having :

we cannot know except if we are sure the ^ is always used in the model as in previous diagram

[edit]

Notice the norm use two times the words member (and not properties) in that sentence, and Class inherits (indirectly) Classifier, so that applies for operations.

As noticed in an other answer the norm says also :

Inherited members may also be shown in a lighter color to help distinguish them from non-inherited **members*.

so again two times members rather than properties, and the fact they use also clearly reference the fact there is an other way which is the ^. So two consistent sentences indicating ^ applies to operations

[warning]

I used BoUML to make the diagrams and in the first you can see "^oper()" but I 'cheated' to do that naming the corresponding operation "^oper", there is no option to show a ^ in a diagram to indicate an operation or other member is inherited




回答2:


No, there is no specific indicator for operations that override operations on a parent class.
If the signature matches it overrides the operation on the parent.




回答3:


The norms says on p. 101:

Inherited members may also be shown in a lighter color to help distinguish them from non-inherited members. A conforming implementation does not need to provide this option.

Sadly, my tool (EA) does not support that.

The simplest method is to duplicate only the operation signatures of those operations you are going to override. That will make it clear that you are overidding something.

By just looking to Class2 there is no way to tell that b is actually an override. However, if someone wants to deal with Class2 he must know that it's a subclass - and thus will know that b is an override.


Note: The UML 2.5 specs are ambigous about the caret use. While (on p. 100) they say

Members that are inherited by a Classifier may be shown on a diagram of that Classifier by prepending a caret ’^’ symbol ...

the syntax below explictely mentions only properties and connectors and this passage

Analogous notations may be used for all NamedElements that are inheritedMembers of a Classifier to indicate that they are inherited.



来源:https://stackoverflow.com/questions/61398067/override-method-in-uml

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