2 ms·
I dislike using mixins for one off -able features...I mean, I do it, but not often. Where mixins really shine is when used in "layers" to modularize system func
by seanmcdirmid 12y ago
I dislike using mixins for one off -able features...I mean, I do it, but not often. Where mixins really shine is when used in "layers" to modularize system functionality that otherwise cross cuts class boundaries. So you can take one aspect of your system...say syntax in a compiler, and separate parsing from type checking in its own layer. This an easy solution to the expression problem and compares favorably with the giant case statements favored in the functional programming community. And its quite nice: you know where functionality X of class C is, its in the C section of file X (i.e. a grid!).
Also, see virtual classes, though very few languages have first-class support for those these days.
Scala mixins (traits) are basically classes that undergo liearized multiple inheritance; they are designed to work well in a statically typed language (they can be used as constraints for type members, and they can refer to those type members themselves, leading to some nice constructions).