Is it bad practice to reference accessors on an extended object from the mixin method? The simplest example:
module WindInstrument def play mouthpiece.blow
In this case, I would simply move the speaker requirement directly to the WindInstrument module, but what about in a more complex scenario, where does it really make sense for the accessor to live on the extended object? Is this just a problem of non-local separation of problems?
Mixins feel useful to add encapsulated behavior that does not require knowledge of the state of the extended object. In fact, my gut tells me that the myxin should not know any condition. If he needs knowledge of the state, I would usually return to one of two options:
Put the state in the class and add it through composition, not through the inheritance hierarchy. My problem is that I know that rubists have the creation of mixes that access the state state, which makes the design more understandable, although less intuitive (for me).
Pass the mouthpiece as a parameter to the module. Even I can say that this seems to hush up the design and feels like an abomination in a ruby worldview.
/ li>
Does this code bother anyone else? I know that there are many smart people who use ruby there, so I assume that my problem. What am I missing? Do I just need to relax? What would you do?
source share