Nothing has improved my Rails apps more than service objects.
A couple of weeks ago, I was asked to help out with an established Rails app.
I found a
User model that included 28 modules.
All but 8 were namespaced under
A core object in your system, used everywhere, and it’s thousands of lines long.
How many features have been bolted onto this model?
When you look at a method, which feature does it belong to?
Madness like this can be sidestepped with service objects.
Let’s start at a time before 28 includes. Let’s start at the beginning. Imagine you’ve started a SaaS business. It’s a help desk. Soon you have clients signing up. Then their users are creating accounts and receiving support.
Want to make your clients happy? Make their users happy. You’ve decided to add a welcome email for those users. It’ll provide a friendly hello and tips on how to use the help desk.
Where does your new code go?Read More