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

Get Groovy 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.