Re: [Lib] Middleclass 4.0.0. Object-Orientation for Lua
Posted: Tue Feb 21, 2017 12:40 pm
Well, it does support a certain kind of multiple inheritance. It might not be what you are looking for though.
In middleclass, every class has a single superclass (or none at all). So in that regard there is no multiple inheritance.
However, middleclass allows sharing behaviour through mixins. This behaviour was inspired by Ruby.
Mixins are basically groups of methods that you can group together and share between several classes. On that regard that works like multiple inheritance. Mixins just don't come with a constructor. This is how middleclass sidesteps the Diamond Problem. You (the middleclass user) are responsible of explicitly building your class instances so that they work correctly with the mixins you include in them.
I recommend you to think hard about using composition instead of inheritance. In the long run, it is usually better to have a physics_body attribute which is an instance of PhysicsBody and a health attribute which is an instance of Health, instead of inheriting directly from both PhysicsBody and Health.