Deconstructing the framework, by Gary Bernhardt
Single Responsibility Principle - A class should have one, and only one, reason to change.
A Rails controller's reasons to change:
- Authentication
- Authorization
- Wrap HTTP in both directions (in: params & headers; out: status codes & headers)
- Manipulate your Active Record models
- Manipulate your database (
user.reload
) - Query the database
- Present models (sum, aggregate)
- Contain view content (flash messages)
- Contain response content (json)
- Routing (conditional redirect)
- Choose content type
- Contain model logic
This is a hypothetical example with the responsibilities decomposed and injected.