当一个 class 从多个 class 继承并具有 UML 中的 classifier 行为时,它应该如何表现?

How should a class behave when it inherit from multiple class with classifier behavior in UML?

给定一个 class 继承层次结构:

上面写着:

class S inherits A1 and A2
class A1 and A2 inherits B1
class A2 inherits B2
class B2 inherits C1

并且对于 class A1、B1、B2、C1,它们设置了 classifierBehavior 属性,而 class S 没有 classiferBehavior。

现在的问题是,当我运行模拟classS时,应该执行什么行为?

在 Cameo Systems Modeler 中,模拟引擎将执行 A1B1 和 [=] 的 classifier 行为29=]B2.

这是正确的方法吗?可以从 UML 规范中导出吗?

我浏览了 UML 2.5 规范并在第 13 页找到了这一段。 288:

If the Class of the receiving object owns a method for the Operation identified in the CallEvent, then that method is the result of the resolution. Otherwise, the superclass of the Class of the receiving object is examined for a method for the Operation, and so on up the generalization hierarchy until a method is found or the root of the hierarchy is reached. If a Class has multiple superclasses, then all of them are examined for a method. If no method is found, or a method is found in more than one ancestor Class along different paths, then the model is ill-formed for this resolution process and it results in no method.

原来如此。定义多个行为是无效的。除此之外,你 can/must 用新的东西覆盖了行为。

UML 规范没有告诉我们如何处理多个继承的 classifierBehavior。但是,fUML 规范说:

fUML 1.5 (page 151): [5] startBehavior [...] create a classifier behavior invocation for each of the types of the object of this object activation which has a classifier behavior [...].

所以,我认为 Cameo 模拟引擎按规定工作,因为超类型在对象具有的类型列表中。而且,这确实有道理。如果某物有两种类型,它应该表现出两种类型的行为。例如,逆变器充电器将对逆变器和充电器做出反应的事件做出反应。

我在规范中没有找到的一件事是,当 Class 有一个 classifierBehavior 时,继承的行为应该被它替换。我认为这是有道理的,因为否则继承的行为将永远无法改变。模拟引擎正是这样做的。

现在,您可能想要 select 继承的行为之一,而不是定义新行为或同时执行它们。这可以通过定义一个空行为来完成,该行为具有对继承的分类器行为的泛化并将其分配为分类器行为。但这在模拟引擎中不起作用。 fUML 排除了 Activity 节点的重新定义,因此这可以解释为什么 Activity 泛化不起作用。但是,“状态机的精确语义”规范允许重新定义状态。

所以我找到的唯一方法是创建一个新的 classifierBehavior 并调用其中一个继承的行为。

解析操作方法的情况不同。例如,它可以有一个输出。这里只有建模者可以决定返回哪个输出。这是通过定义操作的新版本来完成的,该版本重新定义旧版本和 select 来自所需祖先的行为作为新操作的方法。我认为这是相当简单的,没有理由拒绝多重继承。