Skip to content

Instantly share code, notes, and snippets.

@johnnymo87
Last active August 29, 2015 14:01
Show Gist options
  • Save johnnymo87/eea8f9118af338ac46e6 to your computer and use it in GitHub Desktop.
Save johnnymo87/eea8f9118af338ac46e6 to your computer and use it in GitHub Desktop.
Deconstructing the framework

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment