Although overriding virtual classes works the same way as “usual” (single inheritance), the implementation of abstract methods requires a closer look. Listing 6 is an illustration for this purpose.
Listing 6: | abstractmethod |
In this case, the subclass method C::m1() implements both the abstract methods of class A and class B. This is rather significant, because it means the concrete methods of both A and B, which have nothing to do with each other, will use the same implementation provided by C.
In other words, the designer of class A and the designer of B need to agree on what m1 should do. If the two designers have different assumptions about what method m1 should do, then the program will behave strangely when concreteA and concreteB are called.
It should be noted that C::m1 has access to members from A, B and C. As a result, this gives the methods A::concreteA and B::concreteB a potential to access, modify and mess up members beyond those of the superclasses themselves.