Search code examples
umlsysml

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


Given a class inheritance hierarchy:

sample class inheritance hierarchy

which says:

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

and for class A1, B1, B2, C1, they have classifierBehavior attribute setted, while the class S has no classiferBehavior.

Now the question is, when I run simulation for class S, then what behavior should be executed?

In Cameo Systems Modeler, the simulation engine will execute classifier behavior of A1, B1, and B2.

Is this the correct way and can be derived from UML spec?


Solution

  • The UML specification doesn't tell us how to deal with multiple inherited classifierBehaviors. However, the fUML specification says:

    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 [...].

    So, I think the Cameo simulation engine works as specified, since the supertypes are in the list of types an object has. And, it really makes sense. If something is of two types, it should exhibit the behavior of both types. For example an inverter-charger will react to the events an inverter and a charger reacts to.

    One thing I didn't find in the specification is, that when a Class has a classifierBehavior, the inherited behaviors should be replaced by it. I think it makes sense, because otherwise the inherited behaviors could never be changed. The simulation engine does exactly this.

    Now, it is possible, that you want to select one of the inherited behaviors instead of defining a new one or executing them concurrently. This could be done by defining an empty Behavior with a generalization to the inherited classifierBehavior and assign this as classifierBehavior. This doesn't work in the simulation engine though. fUML excludes redefinition of ActivityNodes, so this could be an explanation why Activity generalization doesn't work. However, the "Precise Semantics of State Machines" specification allows redefinition of states.

    So the only way I found was to create a new classifierBehavior and call one of the inherited behaviors.

    The situation for resolving the method of an operation is different. For example it could have an output. Here only the modeler can decide, which output shall be returned. This is done by defining a new version of the operation that redefines both old versions and select the behavior from the desired ancestor as method of the new operation. I think this is fairly straight forward and no reason for rejecting multiple inheritance.