Monday 8 October 2012

Mixins

Most Java developers aren't familiar with mixins. Basically, a mixin is an abstract method. Multiple mixins can be inherited by a subclass (i.e., multiple inheritance). But I guess the key difference here is that mixins are used to collect functionality, as opposed to being specialized by their subclass. This seems like a nuanced philosophical difference.

In Ruby, you can't define instance methods within mixins, but if you include a mixin within a class, the mixin methods become instance methods of that class. The mixin essentially behaves as a superclass. Unfortunately, Java doesn't officially support mixin's or multiple inheritance, but it's something worth knowing.

No comments:

Post a Comment