Implementing multiple inheritance in Groovy
Java classes are only allowed to inherit from a single parent class. Multiple inheritance is only available for interfaces that do not carry any state or implementation details. This is not a drawback, but rather a design choice that allows you to avoid several problems. An example of this is the diamond problem that arises in languages which do employ multiple inheritance. Basically, there is an ambiguity (which method implementation to call) if classes B and C inherit from class A and class D inherits from both B and C. The diamond name comes from the shape of the class diagram formed by the A, B, C, and D.
Groovy still does not allow multiple class inheritance, but offers another approaches for injecting logic that is spread over multiple classes into a single entity.
This recipe will demonstrate a simple use case for the @Mixin
and @Delegate
annotations that can help you simulate multiple inheritance.
Getting ready
We'll start with a simple project...