Skip to content

Instantly share code, notes, and snippets.

@mbriggs
Created February 26, 2013 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbriggs/5039332 to your computer and use it in GitHub Desktop.
Save mbriggs/5039332 to your computer and use it in GitHub Desktop.
# in a simple case, I wish rails worked like this
messages = order.validate # returns errors array
if messages.empty?
order.save!
render 'show'
else
flash[:errors] = messages
render 'edit'
end
# with more complex cases, I would do something like your order.pay method, with even more complex cases
# I would bust out a PayOrder use case controller.
# I don't think 4c is "bad" by any stretch of the imagination. But if you can get away with the null object pattern,
# I think using return values make tracing the code more clear. If you are looking at a function that returns a value,
# you know exactly where execution resumes. If you look at a function that raises, it gets more complecated :)
# On a side note, I don't agree with 2, unless it is in very simple cases. I think the domain model should be an
# abstract representation that is used by use case controllers (or play DCI roles) to do things. Fat models end up with
# giant classes with super complex interactions, DCI/Use case controllers tend to make understanding how things work much
# easier, since coordination logic doesn't get spread out across multiple classes/files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment