Skip to content

Instantly share code, notes, and snippets.

@kchens
Created March 25, 2015 23:42
Show Gist options
  • Select an option

  • Save kchens/c6df20b0df2bbce43f1c to your computer and use it in GitHub Desktop.

Select an option

Save kchens/c6df20b0df2bbce43f1c to your computer and use it in GitHub Desktop.
POODR: Chapter 4 - Creating Flexible Interfaces
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Law of Demeter
# set of coding rules that results in loosely coupled objects. It prohibits
# routing a message to a third object via a second object of a different type.
# Paraphrased: "only talk to your immediate neighbors", "use only one dot"
class Trip
def depart
# "train wrecks"
# if #tire or #rotate change, #depart may change
# trip can't be reused unless it has access to a customer with a bicycle,
# # that has a wheel, that has a tire. Too much context.
customer.bicycle.wheel.tire
customer.bicycle.wheel.rotate
# This is reasonable.
# hash.keys returns an Enumerable
# sort returns an Enumerable
# join returns a String
hash.keys.sort.join(', ')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment