oop-service-objects
Installation
SKILL.md
Service Objects
What it is
A Service Object is a plain Ruby class that encapsulates one business operation. It has a single entry point (conventionally call), accepts input, performs the work, and returns a result. It's a fallback for operations that genuinely don't belong to any model — not a default architecture.
Warning: Rails' own idiom (the DHH/37signals tradition) is to put behavior on models, not to extract it into services. An app full of
*Serviceclasses is the anemic domain model antipattern. Start there. Come back here when you've exhausted simpler options.
Would a fat model / concern / form object do?
Run through this checklist before creating a service object:
- Does it belong on one model? → Add a method to that model.
- Does it involve a form or multi-model input? → Use a form object.
- Is it complex query logic? → Use a query object.
- Is it shared behavior across models? → Use a concern.
- Does it span multiple models with no natural home? → Now consider a service object.