Search code examples
inheritanceinterfacelanguage-lawyerumlclass-diagram

What is the correct representation of inheritance and implementation in the UML class diagram?


So far, I have represented inheritance by a solid line with a closed arrowhead pointing from the subclass to the base class and the implementation by a dashed line with a closed arrowhead pointing from the class to the interface, as in this Wikipedia example:

complex diagram with interface realization by several classes

However, I also found also diagrams in which the implementation of an interface is shown with a solid line. Here is an example in an academic paper.

I therefore wonder what is correct and whether I have understood the semantics of the notation elements correctly. Can someone explain this to me with an authoritative reference to the UML specification?


Solution

  • Your usage is correct.

    The notation for interface realization, which is a dependency, is explained in section 7.7.4:

    A Realization is shown as a dashed line with a triangular arrowhead at the end that corresponds to the realized Element.

    It's illustrated graphically in subsequent section 7.7.5. Alternative notations (lollipop) and their equivalence is explained in section 10.4.4.

    It is possible that an interface is inherited by another interface, in accordance with the generalization/specialization. But an interface cannot be inherited by a class for semantic reasons. Your second example is therefore wrong. (my guess is that it was drawn by someone using a language like C++ where there are no interfaces and interfaces are emulated with abstract classes)