Last active
November 18, 2020 22:47
-
-
Save snuggs/f5ab108a8cf596fbf188 to your computer and use it in GitHub Desktop.
Law of Demeter
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
def store(model) | |
# 99 of 100 times we will only need to call #to_h and be done with model | |
persist model.to_h # Breaks demeter's law | |
# this usually encourages poking around in the model | |
# which is no concern of store | |
end | |
def store(record) #decoupled | |
persist record #because that's all we want to do. | |
# If it doesn't work as expected RTST (Read The Stack Trace) | |
# will probably say something like "Cannot find keys? in persist:22" | |
end | |
store model.to_h #usage | |
# Now #store() AND model#to_h() can be tested independently of one another. | |
# with def store(model); model.to_h; end | |
# an actual model needs to be "let"ed within the context of the store when testing. | |
# The integration of the two is probably a level up in the abstraction and can be stubbed accordingly. |
Also, I fucking hate the idea of multiple representations, other than encoding
Better to have a a Toy and a ToyChildProof
Or an attribute, child_proofed (boolean)
def Toybox.return(toy)
if toy.child_proofed
return 'OK'
else
return 'NOT OK'
end
end
# I'd just return toy.status_message and throw the logic in the toy.
def Toybox.return(toy)
fail Exceptions::Forbidden unless toy.child_proofed
end
def Toybox.return(toy)
fail Exceptions::Forbidden unless toy.child_proofed
@contents << toy
end
def handle request
catch :response do
dispatch request
end
rescue
Responses::ServerErrors::Internal.new
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Human.play child, toy