Skip to content

Instantly share code, notes, and snippets.

View bentona's full-sized avatar
💕
💕

Benton Anderson bentona

💕
💕
View GitHub Profile

Service objects allow Models, Routes, etc to more closely follow the single responsibility principle. The responsibility of a Model is to represent an object’s state, but often the responsibility to know how to i.e. interact with external services leaks into a Model.

A Service is a class that can encapsulate behavior. They are especially useful for capturing business logic, coordinating the interaction of two collaborating objects, and isolating side-effects.

Here are some guidelines to implementing services.

Services should have a single public class method named call

This is to mirror the signature of Proc and represent that the purpose of the class is to encapsulate a single behavior.