如何在序列图中描述继承? [英] How will inheritance is depicted in a sequence diagram?
问题描述
类A的方法m在类B上调用方法n,但类B的源代码不包含n,因为n是从B的一个超类继承的。
Say method m of class A calls method n on class B, but the source code of class B does not contain n, since n is inherited from one of the superclasses of B.
序列图将如何显示?
方法n之间是否存在A和B之间的消息交互,或者它是否与A和超类B用方法n
Will there be message interaction between A and B by the method n or would it be with A and the superclass of B with by method n
推荐答案
如果你要尊重封装的原则,那么交互就完全在<$ c之间$ c> A 和 B
。 B
的实现使用继承的事实与用 A
编写的代码无关 - 它是唯一的世界观是它在 B
上调用方法。
If you're to respect the principle of encapsulation, the interaction would purely be between A
and B
. The fact that B
's implementation uses inheritance is of no concern to the code written in A
- it's sole world view is that it calls the method on B
.
您可以安全地更改中的实现B
且不影响 A
。这是以这种方式绘制交互的另一个原因。
You can safely change the implementation in B
and not affect A
. This is another reason to diagram the interactions this way.
这篇关于如何在序列图中描述继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!