When to use mixins in Ruby
Posted
by
Gilles
on Programmers
See other posts from Programmers
or by Gilles
Published on 2012-06-17T15:15:39Z
Indexed on
2012/06/17
15:22 UTC
Read the original article
Hit count: 281
I am wondering when to use mixins? I have read about them. Many authors compare them to interfaces, abstract classes, etc.
Mixins are modules that are mixed-in and modules are a way to group similar methods, constants and classes together.
I have seen examples where a module for math functions is created. It makes sense to group and reuse such functions but should I only mix these in a class if I am faced with an inheritance situation? Should I mix these in anytime I want to use them in a class?
Should they be used exactly like interfaces in other languages or are there other subtleties?
© Programmers or respective owner