Thursday, June 28, 2007

Little Sugar ( Mixins in Java)

Mixin ?? what is a mixin ...

Thats what i wondered when i cam accross the phrase . A Mixin is a way of adding features to the core functionlaity of a class . It is different from extending the class , cause it generally pertains to adding features not related to the core or default behaviour of a class .

A little example will make things clear . Say you have a small class Person that represents a person wholly . Not if you want to compare 2 instances of Person , you could implement the Comparable interface . By implementing the Comparable interface you add a functionlity that is not directly related to a Person object but is a help ful feature .

So a simple way to implement a Mixin is to implement an interface .. so much for buzz words...

2 comments:

kenliu said...

A Mixin is more than

kenliu said...

Oops. A Mixin is more than simply adding an interface, it's adding actual behavior. When you add an interface to a class in java, it forces you to implement the methods yourself. With a mixin, you get the actual implementation (the method body) added to the class.