by barrkel · 11y ago · 0 comments
From my experience, I'm not a big fan of mixin-heavy development. Mixins need a lot of discipline. A mixin probably shouldn't exist if it doesn't have at least two, if not three different target classes it is mixed into.
I've seen mixins used for almost evil things in Rails. When mixins start adding before filters to controllers, disturbing amounts of magic can occur. You can end up needing to research a whole dependency dag and details of its implementation before you can understand a single method that may not refer to a mixin by symbol at all.
const books = Symbol(“books”);
const BookCollector = {
addToCollection (name) {
this.collection().push(name);
return this;
},
collection () {
return this[books] || (this[books]= []);
}
};Of course I agree with you that mixins need a lot of discipline and I specifically follow the 2-3 different target classes rule. It's really really easy to fall into the trap of making everything a mixin but this is really the wrong way to go about it.