#1951 mixins

jbc Thu 12 Jul 2012

mixins is like an interface where the implementation is there also? and can anyone explain in an easy english how this can help us in programming?

SlimerDude Thu 12 Jul 2012

The following comes to mind:

A lot of people use inheritance when they just want some helper methods. But if you do this, then you've already used up your only line of inheritance.

Mixins enable to you have your helper methods, but also extend from another base class.

It's like a safe version of multiple inheritance.

Of course, the Mixin implementation are optional. If so used, it's like having a default implementation.

jbc Thu 12 Jul 2012

i didnt understand why is it a safe version of multiple inheritance? what do you eman by saying "you've already used up your only line of inheritance"? sorry and thanks

SlimerDude Thu 12 Jul 2012

why is it a safe version of multiple inheritance?

True multiple inheritance gives way to the Diamond Problem.

you've already used up your only line of inheritance

Fantom, like Java and C#, only allows single inheritance. So once you've extended from a base class, you cannot extend from another.

brian Thu 12 Jul 2012

Multiple inheritance is actually only a problem when you have state (fields). With methods/functions it isn't a problem as long as you are clear what happens when you inherit two methods with the same name - in Fantom you just have to override and declare exactly which one you are using.

jbc Thu 12 Jul 2012

nice!! thanks a lot!

Login or Signup to reply.