Good post from Rishi on how to refactor code into Service Objects to improve code maintainability and quality.
ServiceClasses are nothing but plain old ruby classes. But they go a long way to keep your controllers thin and models thin. To show what I mean by this, lets look at some code. This is the code in controller to download data following some set of rules.
This is bad. The controller should not look like this. Comes in Service classes.
The ideology behind service classes is that it should have only one purpose to serve and nothing else.
And I can clearly see a purpose which our new service class should serve and that is to provide the data for our template download and nothing else. I keep the service classes under app/services folder. Also I do not think I need to iterate much on the importance of the name of the service class you choose. It goes without saying that the name should tell the purpose it…
View original post 237 more words