Created
February 26, 2013 15:33
-
-
Save mbriggs/5039332 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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