Hacker News new | ask | show | jobs
by jamesgolick 5136 days ago
Mixins/modules and open classes do not separate your class in to multiple components - merely multiple files. As I explain in the article, for separate components to be useful, they have to be "protected" from each other - encapsulation, in other words.
2 comments

Mixins (well, as they're supposed to be used) do provide encapsulation; specifically, they enforce the boundary between instance scope (e.g. access to instance vars) and method interface. I view them as a part of a coupling continuum:

[instance methods] --- [composed subclasses] --- [mixins] --- [the outside world]

But Modules provide more than that. module_function allows for unattached namespaced functions which can be referenced by full name, relative name, or imported into the local scope. Great way to express functions which are decoupled from instance state--much like the services and policies you're advocating for. It's an under-appreciated aspect of the language, I think.

No doubt - That's just good OOP. Looks like this gem will help people achieve that.