inheritancelanguage-lawyerumlmultiple-inheritancepackage-diagram

Can a merge relation in a UML-Package Diagram lead to multiple inheritance?


I wonder whether the use of the merge-relation in an UML package diagram might lead to multiple inheritance.

Specifically, I was thinking about the following situation:

A package containing a class and its subclass is merged into another package.
Lets assume we have a Package "P1" which contains two classes "A" and "B". "A" inherits from "B". We are trying to merge this package "P1" into a package "P2".

Will this lead to Package "P2" containing a Class "P1::A", which inherits from a class "A" and at the same time inherits from a class "P1::B" (which inherits from a class "B")?


Solution

  • Let's consider your merge example:

    enter image description here

    The package P2 contains a class B and a class A inheriting from that B. Since there are no A nor B defined, the P2 classes are deep copies of the ones defined in P1 in view of the following UML transformation rule:

    (The default rule) Merged or receiving elements for which there is no matching element are deep copied into the resulting package.

    But what is the relationship between the resulting class A in P2 and the class A in P1? You assumed inheritance and therefore saw multiple inheritance. This sounds logic, as one would expect that instances of P2::A are also instances of P1::A, which would look like inheritance. But this is not what the UML specs say. Both types share their unqualified name, and are simply substitutable, without any inheritance:

    A Substitution is a relationship between two Classifiers which signifies that the substitutingClassifier complies with the contract specified by the contract Classifier. This implies that instances of the substitutingClassifier are runtime substitutable where instances of the contract Classifier are expected. The Substitution dependency denotes runtime substitutability that is not based on specialization. Substitution, unlike specialization, does not imply inheritance of structure, but only compliance of publicly available contracts.

    It's somewhat difficult to see in practice, as many languages do not allow substitutability outside the context of inheritance or interface realization. Moreover, the UML specs add to the confusion by making a comparison between merge and inheritance, to conduct some reasoning by analogy.

    By the way, this conclusion regarding your question does not mean that merge can never lead to multiple inheritance, as the following example shows:

    enter image description here