|
|
|
|
|
by urbanautomaton
5003 days ago
|
|
I agree that using Observers (at least as embodied in Rails' implementation) can lead to a fearful (and hard-to-debug) mess. I feel that our approach differs, though, in forcing the notification to be explicit, as opposed to tied to object lifecycle callbacks. It's plain to see in our controller what event is being announced, and trivial to find all listeners that respond to that event. No familiarity with the model being manipulated is required, because it's got nothing to do with either the event announcement or the responses to it. And by providing a centralised event dispatch system, there's a simple point of entry for debugging. We did consider the service object approach, as detailed early in the blog - for me, though, it feels wrong to end up with a bunch of service objects, each with a semi-random grab-bag of dependencies and responsibilities. One of our main aims was to reduce the random scattering throughout our app of various calls, because the coupling was making it hard to reliably effect change when necessary. Service objects don't address this, unfortunately. We still make use of them, but to my mind a CommentCreationService should only be concerned with creating valid comments - not with emailing or rewarding users. |
|