Created
March 25, 2015 23:42
-
-
Save kchens/c6df20b0df2bbce43f1c to your computer and use it in GitHub Desktop.
POODR: Chapter 4 - Creating Flexible Interfaces
This file contains hidden or 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
| # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | |
| # 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