Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go Ahead, Make a Mess - Sandi Metz

66ad01cf37c098bfdb76906a490e018f?s=47 Sandi Metz
September 15, 2012

Go Ahead, Make a Mess - Sandi Metz

This talk shows how to use Object-Oriented Design to create the best kinds of messes, those that let you get software out the door today without regretting your actions tomorrow.

This is the 45 minute version, given at GoGaRuCo, Sept. 15 2012.

66ad01cf37c098bfdb76906a490e018f?s=128

Sandi Metz

September 15, 2012
Tweet

Transcript

  1. @sandimetz Sept 2012 Go Ahead Make a Mess Sandi Metz

    1 Friday, September 14, 2012
  2. @sandimetz Sept 2012 Life Cycle of a Rails Project 2

    Friday, September 14, 2012
  3. @sandimetz Sept 2012 Start Beta 1.0 2.0 Today Satisfaction Timeline

    3 Friday, September 14, 2012
  4. @sandimetz Sept 2012 Start Beta 1.0 2.0 Today Satisfaction Timeline

    4 Friday, September 14, 2012
  5. @sandimetz Sept 2012 Satisfaction 5 Friday, September 14, 2012

  6. @sandimetz Sept 2012 Satisfaction Those who cannot remember the past

    are condemned to repeat it. 5 Friday, September 14, 2012
  7. @sandimetz Sept 2012 6 Friday, September 14, 2012

  8. @sandimetz Sept 2012 Satisfaction 7 Friday, September 14, 2012

  9. @sandimetz Sept 2012 The Mess 8 Friday, September 14, 2012

  10. @sandimetz Sept 2012 9 Friday, September 14, 2012

  11. 10 Friday, September 14, 2012

  12. @sandimetz Sept 2012 Knowledge 11 Friday, September 14, 2012

  13. 12 Friday, September 14, 2012

  14. 13 Friday, September 14, 2012

  15. @sandimetz Sept 2012 Dependencies 14 Friday, September 14, 2012

  16. 15 Friday, September 14, 2012

  17. 16 Friday, September 14, 2012

  18. @sandimetz Sept 2012 Stability 17 Friday, September 14, 2012

  19. 18 Friday, September 14, 2012

  20. 19 Friday, September 14, 2012

  21. 20 Friday, September 14, 2012

  22. @sandimetz Sept 2012 Hope 21 Friday, September 14, 2012

  23. 22 Friday, September 14, 2012

  24. @sandimetz Sept 2012 Start Beta 1.0 2.0 Today Satisfaction Timeline

    23 Friday, September 14, 2012
  25. @sandimetz Sept 2012 Object-Oriented Design Stop worrying and learn to

    love the mess 24 Friday, September 14, 2012
  26. 25 Friday, September 14, 2012

  27. Label the Knowledge 26 Friday, September 14, 2012

  28. Label the Knowledge Complicate the Code 27 Friday, September 14,

    2012
  29. Label the Knowledge Complicate the Code Isolate the Instability 28

    Friday, September 14, 2012
  30. Label the Knowledge Complicate the Code Isolate the Instability Manage

    the Mess 29 Friday, September 14, 2012
  31. @sandimetz Sept 2012 Example #1 Label the Knowledge 30 Friday,

    September 14, 2012
  32. @sandimetz Sept 2012 Example #1 class  Game    def  shock_cost

           Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math        #  ...            #  which  eventually  return        cost    end     31 Friday, September 14, 2012
  33. @sandimetz Sept 2012 Example #1 class  Game    def  shock_cost

           Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math        #  ...            #  which  eventually  return        cost    end     31 Friday, September 14, 2012
  34. @sandimetz Sept 2012 Example #1 class  Game    def  shock_cost

           Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math        #  ...            #  which  eventually  return        cost    end     31 Friday, September 14, 2012
  35. @sandimetz Sept 2012 Example #1 class  Game    def  shock_cost

           Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math        #  ...            #  which  eventually  return        cost    end     31 Friday, September 14, 2012
  36. @sandimetz Sept 2012 Example #1 class  Game    def  shock_cost

           Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math        #  ...            #  which  eventually  return        cost    end     31 Friday, September 14, 2012
  37. @sandimetz Sept 2012 Example #1 class  Game    def  shock_cost

           Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math        #  ...            #  which  eventually  return        cost    end     MESS 31 Friday, September 14, 2012
  38. @sandimetz Sept 2012 Example #1 class  Game    def  shock_cost

           Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math        #  ...            #  which  eventually  return        cost    end     Omega Mess 31 Friday, September 14, 2012
  39. 32 Friday, September 14, 2012

  40. Omega Mess 32 Friday, September 14, 2012

  41. Omega Mess End of the Line 32 Friday, September 14,

    2012
  42. Omega Mess End of the Line No Dependencies 32 Friday,

    September 14, 2012
  43. Omega Mess End of the Line No Dependencies No Dependents

    32 Friday, September 14, 2012
  44. @sandimetz Sept 2012 33 Friday, September 14, 2012

  45. @sandimetz Sept 2012 33 Friday, September 14, 2012

  46. @sandimetz Sept 2012 33 Friday, September 14, 2012

  47. @sandimetz Sept 2012 33 Friday, September 14, 2012

  48. @sandimetz Sept 2012 33 Friday, September 14, 2012

  49. @sandimetz Sept 2012 33 Friday, September 14, 2012

  50. @sandimetz Sept 2012 33 Friday, September 14, 2012

  51. @sandimetz Sept 2012 34 Friday, September 14, 2012

  52. @sandimetz Sept 2012 Knowledge Stability 34 Friday, September 14, 2012

  53. @sandimetz Sept 2012 External Knowledge Stability 34 Friday, September 14,

    2012
  54. @sandimetz Sept 2012 Internal External Knowledge Stability 34 Friday, September

    14, 2012
  55. @sandimetz Sept 2012 Internal External Knowledge Stability Low High 34

    Friday, September 14, 2012
  56. @sandimetz Sept 2012 Internal External Knowledge Stability Low High 34

    Friday, September 14, 2012
  57. @sandimetz Sept 2012 Internal External Knowledge Stability Low High 34

    Friday, September 14, 2012
  58. @sandimetz Sept 2012 Internal External Knowledge Stability Low High 34

    Friday, September 14, 2012
  59. @sandimetz Sept 2012 Internal External Knowledge Stability Low High 34

    Friday, September 14, 2012
  60. @sandimetz Sept 2012 Internal External Knowledge Stability Low High 34

    Friday, September 14, 2012
  61. @sandimetz Sept 2012 Internal External Knowledge Stability Low High 34

    Friday, September 14, 2012
  62. @sandimetz Sept 2012 Dependencies Shock 35 Friday, September 14, 2012

  63. @sandimetz Sept 2012 Dependencies Shock Game 35 Friday, September 14,

    2012
  64. @sandimetz Sept 2012 36 Friday, September 14, 2012

  65. @sandimetz Sept 2012 Omega 36 Friday, September 14, 2012

  66. @sandimetz Sept 2012 Omega 36 Friday, September 14, 2012

  67. 37 Friday, September 14, 2012

  68. Omega Mess 37 Friday, September 14, 2012

  69. Omega Mess Hides behind the message 37 Friday, September 14,

    2012
  70. @sandimetz Sept 2012 class  Game    def  shock_cost    

       Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math            #  ...            #  which  eventually  return        cost    end     end Example #1 38 Friday, September 14, 2012
  71. @sandimetz Sept 2012 class  Game    def  shock_cost    

       Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math            #  ...            #  which  eventually  return        cost    end     end It’s not about the code Example #1 38 Friday, September 14, 2012
  72. @sandimetz Sept 2012 39 Friday, September 14, 2012

  73. @sandimetz Sept 2012 It’s about the message 39 Friday, September

    14, 2012
  74. 40 Friday, September 14, 2012

  75. 41 Friday, September 14, 2012

  76. Interlude 42 Friday, September 14, 2012

  77. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose 43 Friday, September 14, 2012
  78. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose 43 Friday, September 14, 2012
  79. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose 43 Friday, September 14, 2012
  80. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Public API 43 Friday, September 14, 2012
  81. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Public API Private Behavior 43 Friday, September 14, 2012
  82. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Public API Private Behavior Dependencies 43 Friday, September 14, 2012
  83. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Public API Private Behavior Dependencies Expose 43 Friday, September 14, 2012
  84. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Public API Private Behavior Dependencies Expose Hide 43 Friday, September 14, 2012
  85. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Public API Private Behavior Dependencies Expose Hide Minimize 43 Friday, September 14, 2012
  86. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Public API Private Behavior Dependencies Expose Hide Minimize Move 43 Friday, September 14, 2012
  87. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    cost calculation Game depends on 3. cost message 4. Shock class name 5. cost receiver 44 Friday, September 14, 2012
  88. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    cost calculation Game depends on 3. cost message 4. Shock class name 5. cost receiver 44 Friday, September 14, 2012
  89. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    cost calculation Game depends on 3. cost message 4. Shock class name 5. cost receiver 44 Friday, September 14, 2012
  90. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    cost calculation Game depends on 3. cost message 4. Shock class name 5. cost receiver 45 Friday, September 14, 2012
  91. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 46 Friday, September 14, 2012
  92. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 1 46 Friday, September 14, 2012
  93. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method (expose)

    2. cost calculation Game depends on 3. cost message 4. Shock class name 5. cost receiver 47 Friday, September 14, 2012
  94. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method (expose)

    2. cost calculation Game depends on 3. cost message 4. Shock class name 5. cost receiver 47 Friday, September 14, 2012
  95. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 1 48 Friday, September 14, 2012
  96. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 1 2 48 Friday, September 14, 2012
  97. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method (expose)

    2. cost calculation (hide) Game depends on 3. cost message 4. Shock class name 5. cost receiver 49 Friday, September 14, 2012
  98. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method (expose)

    2. cost calculation (hide) Game depends on 3. cost message 4. Shock class name 5. cost receiver 49 Friday, September 14, 2012
  99. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method (expose)

    2. cost calculation (hide) Game depends on 3. cost message 4. Shock class name 5. cost receiver 49 Friday, September 14, 2012
  100. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 50 Friday, September 14, 2012
  101. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 3 50 Friday, September 14, 2012
  102. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    cost calculation Game depends on 3. cost message (minimize) 4. Shock class name 5. cost receiver 51 Friday, September 14, 2012
  103. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    cost calculation Game depends on 3. cost message (minimize) 4. Shock class name 5. cost receiver 51 Friday, September 14, 2012
  104. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 3 52 Friday, September 14, 2012
  105. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 4 5 3 52 Friday, September 14, 2012
  106. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 4 5 3 52 Friday, September 14, 2012
  107. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide ? Minimize Move 4 5 3 52 Friday, September 14, 2012
  108. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    cost calculation Game depends on 3. cost message (minimize) 4. Shock class name 5. cost receiver ??? 53 Friday, September 14, 2012
  109. @sandimetz Sept 2012 class  Game    def  shock_cost    

       Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math            #  ...            #  which  eventually  return        cost    end     end Example #1 54 Friday, September 14, 2012
  110. @sandimetz Sept 2012 What is the future cost of doing

    nothing now? 55 Friday, September 14, 2012
  111. @sandimetz Sept 2012 class  Game    def  shock_cost    

       Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math            #  ...            #  which  eventually  return        cost    end     end Example #1 56 Friday, September 14, 2012
  112. @sandimetz Sept 2012 class  Game    def  shock_cost    

       Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math            #  ...            #  which  eventually  return        cost    end     end I would inject this dependency Example #1 56 Friday, September 14, 2012
  113. @sandimetz Sept 2012 class  Game    def  shock_cost    

       Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math            #  ...            #  which  eventually  return        cost    end     end I would inject this dependency I would neaten this mess Example #1 56 Friday, September 14, 2012
  114. @sandimetz Sept 2012 class  Game    def  shock_cost    

       Shock.new.cost    end end class  Shock    def  cost            #  lines  of  messy  math            #  ...            #  which  eventually  return        cost    end     end I would inject this dependency I would neaten this mess You might not Example #1 56 Friday, September 14, 2012
  115. 57 Friday, September 14, 2012

  116. 58 Friday, September 14, 2012

  117. @sandimetz Sept 2012 Example #2 Complicate the code 59 Friday,

    September 14, 2012
  118. @sandimetz Sept 2012 Example #2 Complicate the code Shocks vary

    in cost 59 Friday, September 14, 2012
  119. @sandimetz Sept 2012 Example #2 class  Game    def  shock_cost(type)

           Shock.new(type).cost    end end 60 Friday, September 14, 2012
  120. @sandimetz Sept 2012 Example #2 class  Game    def  shock_cost(type)

           Shock.new(type).cost    end end 60 Friday, September 14, 2012
  121. @sandimetz Sept 2012 Example #2 class  Game    def  shock_cost(type)

           Shock.new(type).cost    end end 60 Friday, September 14, 2012
  122. @sandimetz Sept 2012 Example #2 class  Shock    attr_reader  :type

       def  initialize(type)  #  ...    def  cost        case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end     61 Friday, September 14, 2012
  123. @sandimetz Sept 2012 Example #2 class  Shock    attr_reader  :type

       def  initialize(type)  #  ...    def  cost        case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end     61 Friday, September 14, 2012
  124. @sandimetz Sept 2012 Example #2 class  Shock    attr_reader  :type

       def  initialize(type)  #  ...    def  cost        case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end     61 Friday, September 14, 2012
  125. @sandimetz Sept 2012 Example #2 class  Shock    attr_reader  :type

       def  initialize(type)  #  ...    def  cost        case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end     61 Friday, September 14, 2012
  126. @sandimetz Sept 2012 Example #2 class  Shock    attr_reader  :type

       def  initialize(type)  #  ...    def  cost        case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end     61 Friday, September 14, 2012
  127. @sandimetz Sept 2012 62 Friday, September 14, 2012

  128. @sandimetz Sept 2012 62 Friday, September 14, 2012

  129. @sandimetz Sept 2012 Omega? 62 Friday, September 14, 2012

  130. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    cost calculation 3. 4. 63 Friday, September 14, 2012
  131. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    cost calculation 3. 4. 63 Friday, September 14, 2012
  132. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations 3. four shock types 4. which type gets what calculation 64 Friday, September 14, 2012
  133. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations 3. four shock types 4. which type gets what calculation 64 Friday, September 14, 2012
  134. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations 3. four shock types 4. which type gets what calculation 64 Friday, September 14, 2012
  135. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations 3. four shock types 4. which type gets what calculation 65 Friday, September 14, 2012
  136. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations 3. four shock types 4. which type gets what calculation Omega Mess? 66 Friday, September 14, 2012
  137. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations 3. four shock types 4. which type gets what calculation Omega Mess? 66 Friday, September 14, 2012
  138. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations 3. four shock types 4. which type gets what calculation Meta Knowledge 67 Friday, September 14, 2012
  139. 68 Friday, September 14, 2012

  140. Meta Knowledge 68 Friday, September 14, 2012

  141. Meta Knowledge Knowledge about Knowledge 68 Friday, September 14, 2012

  142. 69 Friday, September 14, 2012

  143. Meta Knowledge 69 Friday, September 14, 2012

  144. Meta Knowledge The Domain of Design 69 Friday, September 14,

    2012
  145. 70 Friday, September 14, 2012

  146. Interlude 71 Friday, September 14, 2012

  147. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations 3. four shock types 4. which type gets what calculation 72 Friday, September 14, 2012
  148. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations 3. four shock types 4. which type gets what calculation 72 Friday, September 14, 2012
  149. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations 3. four shock types 4. which type gets what calculation 72 Friday, September 14, 2012
  150. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 2 73 Friday, September 14, 2012
  151. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 2 73 Friday, September 14, 2012
  152. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations (move) 3. four shock types 4. which type gets what calculation 74 Friday, September 14, 2012
  153. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations (move) 3. four shock types 4. which type gets what calculation 74 Friday, September 14, 2012
  154. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 75 Friday, September 14, 2012
  155. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 3 75 Friday, September 14, 2012
  156. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations (move) 3. four shock types (move) 4. which type gets what calculation 76 Friday, September 14, 2012
  157. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations (move) 3. four shock types (move) 4. which type gets what calculation 76 Friday, September 14, 2012
  158. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 77 Friday, September 14, 2012
  159. @sandimetz Sept 2012 Knowledge Plot Stable Unstable Within My Purpose

    Outside of My Purpose Expose Hide Minimize Move 4 77 Friday, September 14, 2012
  160. @sandimetz Sept 2012 Knowledge Shock knows 1. cost method 2.

    four shock cost calculations (move) 3. four shock types (move) 4. which type gets what calculation (min) 78 Friday, September 14, 2012
  161. @sandimetz Sept 2012 Preference 79 Friday, September 14, 2012

  162. @sandimetz Sept 2012 Preference Send a message 79 Friday, September

    14, 2012
  163. @sandimetz Sept 2012 Preference Send a message rather than implement

    behavior 79 Friday, September 14, 2012
  164. @sandimetz Sept 2012 Move it 80 Friday, September 14, 2012

  165. @sandimetz Sept 2012 Move it Find the message 80 Friday,

    September 14, 2012
  166. @sandimetz Sept 2012 Move it Find the message (Create the

    object) 80 Friday, September 14, 2012
  167. @sandimetz Sept 2012 Move it Find the message (Create the

    object) Send the message 80 Friday, September 14, 2012
  168. 81 Friday, September 14, 2012

  169. @sandimetz Sept 2012 Example #3 Composition 82 Friday, September 14,

    2012
  170. @sandimetz Sept 2012 #3 Composition    def  cost    

       case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end 83 Friday, September 14, 2012
  171. @sandimetz Sept 2012 #3 Composition    def  cost    

       case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end 83 Friday, September 14, 2012
  172. @sandimetz Sept 2012 #3 Composition    def  cost    

       case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end 83 Friday, September 14, 2012
  173. @sandimetz Sept 2012 #3 Composition    def  cost    

       case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end What’s the message? 83 Friday, September 14, 2012
  174. @sandimetz Sept 2012 #3 Composition    def  cost    

       case  type        when  :front            someObligingObj.compute        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end 84 Friday, September 14, 2012
  175. @sandimetz Sept 2012 #3 Composition    def  cost    

       case  type        when  :front            someObligingObj.compute        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end ??? 84 Friday, September 14, 2012
  176. @sandimetz Sept 2012    def  cost        case

     type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end #3 Composition class  FrontShockCost    def  compute        #  the  original  mess    end end 85 Friday, September 14, 2012
  177. @sandimetz Sept 2012    def  cost        case

     type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end #3 Composition class  FrontShockCost    def  compute        #  the  original  mess    end end 85 Friday, September 14, 2012
  178. @sandimetz Sept 2012    def  cost        case

     type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end #3 Composition class  FrontShockCost    def  compute        #  the  original  mess    end end Hide the Mess 85 Friday, September 14, 2012
  179. @sandimetz Sept 2012    def  cost        case

     type        when  :front            FrontShockCost.new.compute        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end #3 Composition class  FrontShockCost    def  compute        #  the  original  mess    end end 86 Friday, September 14, 2012
  180. @sandimetz Sept 2012    def  cost        case

     type        when  :front            FrontShockCost.new.compute        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end #3 Composition class  FrontShockCost    def  compute        #  the  original  mess    end end Send the Message 86 Friday, September 14, 2012
  181. @sandimetz Sept 2012    def  cost        case

     type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end #3 Composition 87 Friday, September 14, 2012
  182. @sandimetz Sept 2012    def  cost        case

     type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end #3 Composition 87 Friday, September 14, 2012
  183. @sandimetz Sept 2012    def  cost        case

     type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end #3 Composition 87 Friday, September 14, 2012
  184. @sandimetz Sept 2012    def  cost        case

     type        when  :front            #  the  original  mess        when  :rear            #  a  slightly  different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end #3 Composition Hide all of the Messes 87 Friday, September 14, 2012
  185. @sandimetz Sept 2012 #3 Composition class  FrontShockCost    def  compute

           #  the  original  mess    end end class  RearShockCost    def  compute        #  slightly  changed  mess    end end #  etc 88 Friday, September 14, 2012
  186. @sandimetz Sept 2012 #3 Composition class  FrontShockCost    def  compute

           #  the  original  mess    end end class  RearShockCost    def  compute        #  slightly  changed  mess    end end #  etc 88 Friday, September 14, 2012
  187. @sandimetz Sept 2012 #3 Composition class  FrontShockCost    def  compute

           #  the  original  mess    end end class  RearShockCost    def  compute        #  slightly  changed  mess    end end #  etc 88 Friday, September 14, 2012
  188. @sandimetz Sept 2012 #3 Composition class  Shock    def  cost(type)

           case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end 89 Friday, September 14, 2012
  189. @sandimetz Sept 2012 #3 Composition class  Shock    def  cost(type)

           case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end Send the Message 89 Friday, September 14, 2012
  190. @sandimetz Sept 2012 #3 Composition class  Shock    def  cost(type)

           case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end 90 Friday, September 14, 2012
  191. @sandimetz Sept 2012 #3 Composition class  Shock    def  cost(type)

           case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end 90 Friday, September 14, 2012
  192. @sandimetz Sept 2012 #3 Composition class  Shock    def  cost(type)

           case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end Really? 90 Friday, September 14, 2012
  193. @sandimetz Sept 2012 Meta Knowledge Shock knows 1. cost method

    2. four shock cost calculations 3. four shock types 4. which type gets what calculation 91 Friday, September 14, 2012
  194. @sandimetz Sept 2012 Meta Knowledge Shock knows 1. cost method

    2. four shock cost calculations 3. four shock types 4. which type gets what calculation 91 Friday, September 14, 2012
  195. @sandimetz Sept 2012 Meta Knowledge Shock knows 1. cost method

    2. four ShockCostxx classes 3. four shock types 4. which type gets what calculation 92 Friday, September 14, 2012
  196. @sandimetz Sept 2012 Meta Knowledge Shock knows 1. cost method

    2. four ShockCostxx classes 3. four shock types 4. which type gets what calculation 93 Friday, September 14, 2012
  197. @sandimetz Sept 2012 Meta Knowledge Shock knows 1. cost method

    2. four ShockCostxx classes 3. four shock types 4. which type gets what class 94 Friday, September 14, 2012
  198. @sandimetz Sept 2012 Good News Calculations are isolated 95 Friday,

    September 14, 2012
  199. @sandimetz Sept 2012 Bad News Still have dependencies 96 Friday,

    September 14, 2012
  200. @sandimetz Sept 2012 class  Shock    def  cost(type)    

       case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end #3 Composition 97 Friday, September 14, 2012
  201. @sandimetz Sept 2012 class  Shock    def  cost(type)    

       case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end #3 Composition 97 Friday, September 14, 2012
  202. @sandimetz Sept 2012 class  Shock    def  cost(type)    

       case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end when  :front    FrontShockCost.new.compute #3 Composition 98 Friday, September 14, 2012
  203. @sandimetz Sept 2012 class  Shock    def  cost(type)    

       case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end when  :foo    FooShockCost.new.compute #3 Composition 98 Friday, September 14, 2012
  204. @sandimetz Sept 2012 class  Shock    def  cost(type)    

       case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end when  :foo    FooShockCost.new.compute #3 Composition 98 Friday, September 14, 2012
  205. @sandimetz Sept 2012 class  Shock    def  cost(type)    

       case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end when  :foo    FooShockCost.new.compute #3 Composition Convention over con guration 98 Friday, September 14, 2012
  206. @sandimetz Sept 2012 class  Shock    def  cost(type)    

       case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end when  :foo    FooShockCost.new.compute class_name  =  type.to_s.titleize  +  "ShockCost" #3 Composition Convention over con guration 98 Friday, September 14, 2012
  207. @sandimetz Sept 2012 class  Shock    def  cost(type)    

       case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end class_name  =  type.to_s.titleize  +  "ShockCost" eval(class_name).new.compute #3 Composition Convention over con guration when  :foo    FooShockCost.new.compute 99 Friday, September 14, 2012
  208. @sandimetz Sept 2012 class  Shock    def  cost(type)    

       case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end class_name  =  type.to_s.titleize  +  "ShockCost" eval(class_name).new.compute Object.const_get(class_name).new.compute #3 Composition Convention over con guration when  :foo    FooShockCost.new.compute 100 Friday, September 14, 2012
  209. @sandimetz Sept 2012 class  Shock    def  cost(type)    

       case  type        when  :front            FrontShockCost.new.compute        when  :rear            RearShockCost.new.compute        when  :lefty            LeftyShockCost.new.compute        else            ShockCost.new.compute        end    end    #  ... end class_name  =  type.to_s.titleize  +  "ShockCost" eval(class_name).new.compute Object.const_get(class_name).new.compute class_name.constantize.new.compute #3 Composition Convention over con guration when  :foo    FooShockCost.new.compute 101 Friday, September 14, 2012
  210. @sandimetz Sept 2012 Example #3 class  Shock    def  cost(type)

         class_name  =  (type.to_s.titleize  +  "ShockCost")      class_name.constantize.new.compute    end end 102 Friday, September 14, 2012
  211. @sandimetz Sept 2012 Example #3 class  Shock    def  cost(type)

         class_name  =  (type.to_s.titleize  +  "ShockCost")      class_name.constantize.new.compute    end end 102 Friday, September 14, 2012
  212. @sandimetz Sept 2012 Example #3 class  Shock    def  cost(type)

         class_name  =  (type.to_s.titleize  +  "ShockCost")      class_name.constantize.new.compute    end end Factory 102 Friday, September 14, 2012
  213. @sandimetz Sept 2012 We <3 Factories 103 Friday, September 14,

    2012
  214. @sandimetz Sept 2012 Meta Knowledge Shock knows 1. cost method

    2. four ShockCostxx classes 3. four shock types 4. which type gets what class 104 Friday, September 14, 2012
  215. @sandimetz Sept 2012 Meta Knowledge Shock knows 1. cost method

    2. four ShockCostxx classes 3. four shock types 4. which type gets what class 104 Friday, September 14, 2012
  216. @sandimetz Sept 2012 Meta Knowledge Shock knows 1. cost method

    2. four ShockCostxx classes 3. four shock types 4. which type gets what class 104 Friday, September 14, 2012
  217. @sandimetz Sept 2012 Meta Knowledge Shock knows 1. cost method

    2. four ShockCostxx classes 3. four shock types 4. which type gets what class 104 Friday, September 14, 2012
  218. @sandimetz Sept 2012 Meta Knowledge Shock knows 1. cost method

    2. the convention 105 Friday, September 14, 2012
  219. @sandimetz Sept 2012 Before #3 Composition    def  cost  

         case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly              #    different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end 106 Friday, September 14, 2012
  220. @sandimetz Sept 2012 Before #3 Composition    def  cost  

         case  type        when  :front            #  the  original  mess        when  :rear            #  a  slightly              #    different  mess        when  :lefty            #  another  variant        else            #  and  so  on.        end    end Many changes affect this code 106 Friday, September 14, 2012
  221. @sandimetz Sept 2012 After Example #3 class  Shock    def

     cost(type)      class_name  =  (type.to_s.titleize  +  "ShockCost")      class_name.constantize.new.compute    end end 107 Friday, September 14, 2012
  222. @sandimetz Sept 2012 After Example #3 class  Shock    def

     cost(type)        to_class(type).new.compute    end    def  to_class(type)        (type.to_s.titleize  +  "ShockCost").constantize    end end 108 Friday, September 14, 2012
  223. @sandimetz Sept 2012 After Example #3 class  Shock    def

     cost(type)        to_class(type).new.compute    end    def  to_class(type)        (type.to_s.titleize  +  "ShockCost").constantize    end end Few changes affect this code 109 Friday, September 14, 2012
  224. @sandimetz Sept 2012 After Example #3 class  FrontShockCost    def

     compute        #  the  original  mess    end end class  Shock    def  cost(type)        to_class(type).new.compute    end    def  to_class(type)        (type.to_s.titleize  +  "ShockCost").constantize    end end Few changes affect this code 109 Friday, September 14, 2012
  225. @sandimetz Sept 2012 After Example #3 class  FrontShockCost    def

     compute        #  the  original  mess    end end class  Shock    def  cost(type)        to_class(type).new.compute    end    def  to_class(type)        (type.to_s.titleize  +  "ShockCost").constantize    end end class  RearShockCost    def  compute        #  slightly  changed  mess    end end Few changes affect this code 109 Friday, September 14, 2012
  226. @sandimetz Sept 2012 After Example #3 class  FrontShockCost    def

     compute        #  the  original  mess    end end class  Shock    def  cost(type)        to_class(type).new.compute    end    def  to_class(type)        (type.to_s.titleize  +  "ShockCost").constantize    end end class  RearShockCost    def  compute        #  slightly  changed  mess    end end Etc... Few changes affect this code 109 Friday, September 14, 2012
  227. @sandimetz Sept 2012 After Example #3 class  FrontShockCost    def

     compute        #  the  original  mess    end end class  Shock    def  cost(type)        to_class(type).new.compute    end    def  to_class(type)        (type.to_s.titleize  +  "ShockCost").constantize    end end class  RearShockCost    def  compute        #  slightly  changed  mess    end end Etc... Few changes affect this code Need a new one? Follow the convention! 109 Friday, September 14, 2012
  228. @sandimetz Sept 2012 Composition 110 Friday, September 14, 2012

  229. @sandimetz Sept 2012 Shock ? 111 Friday, September 14, 2012

  230. @sandimetz Sept 2012 Shock 111 Friday, September 14, 2012

  231. @sandimetz Sept 2012 Shock 112 Friday, September 14, 2012

  232. @sandimetz Sept 2012 Shock 112 Friday, September 14, 2012

  233. @sandimetz Sept 2012 Shock 113 Friday, September 14, 2012

  234. @sandimetz Sept 2012 Shock 114 Friday, September 14, 2012

  235. @sandimetz Sept 2012 Shock 115 Friday, September 14, 2012

  236. @sandimetz Sept 2012 Shock 115 Friday, September 14, 2012

  237. @sandimetz Sept 2012 Shock 116 Friday, September 14, 2012

  238. @sandimetz Sept 2012 Shock 116 Friday, September 14, 2012

  239. @sandimetz Sept 2012 The Role 117 Friday, September 14, 2012

  240. @sandimetz Sept 2012 118 Friday, September 14, 2012

  241. @sandimetz Sept 2012 118 Friday, September 14, 2012

  242. @sandimetz Sept 2012 Reprise Find the message (Create the object)

    Send the message 119 Friday, September 14, 2012
  243. @sandimetz Sept 2012 Omega Mess 120 Friday, September 14, 2012

  244. @sandimetz Sept 2012 Omega Mess Hide It 120 Friday, September

    14, 2012
  245. @sandimetz Sept 2012 Meta Knowledge 121 Friday, September 14, 2012

  246. @sandimetz Sept 2012 Meta Knowledge Organize It 121 Friday, September

    14, 2012
  247. 122 Friday, September 14, 2012

  248. 123 Friday, September 14, 2012

  249. 124 Friday, September 14, 2012

  250. Depend on Stability 125 Friday, September 14, 2012

  251. Depend on Stability Find the Message 126 Friday, September 14,

    2012
  252. Isolate Uncertainty 127 Friday, September 14, 2012

  253. Isolate Uncertainty Hide the Mess 128 Friday, September 14, 2012

  254. We Stand on the Shoulders of Giants 129 Friday, September

    14, 2012
  255. 130 Friday, September 14, 2012

  256. 131 Friday, September 14, 2012

  257. 132 Friday, September 14, 2012

  258. 133 Friday, September 14, 2012

  259. 134 Friday, September 14, 2012

  260. 135 Friday, September 14, 2012

  261. Thanks Sandi Metz 136 Friday, September 14, 2012

  262. http://www.flickr.com/photos/slumadridcampus/5736110401/ http://www.flickr.com/photos/jennifermarquez/4441957235/ http://www.flickr.com/photos/58789412@N00/4106497024/ http://www.flickr.com/photos/27927484@N00/264072199/ http://www.flickr.com/photos/alexindigo/2572565946/in/photostream/ http://www.flickr.com/photos/moje_moje/4500967490/ http://www.flickr.com/photos/dr_nixon/4366089630/ http://www.flickr.com/photos/question_everything/4778500858/ http://www.flickr.com/photos/thegforcers/6202236364/in/photostream/ http://www.flickr.com/photos/jeffhester/2785524078/

    http://www.flickr.com/photos/thegforcers/6040964794/in/photostream/ http://www.flickr.com/photos/magnus_akselvoll/4741056713/ http://www.flickr.com/photos/chiotsrun/6553699405/ http://www.flickr.com/photos/45682148@N05/7943889710/ http://www.flickr.com/photos/piper/393928412/ http://www.flickr.com/photos/thegforcers/6202237588/in/photostream/ http://www.flickr.com/photos/juju2nantes/5895167252/ Credits 137 Friday, September 14, 2012
  263. http://www.flickr.com/photos/harlequeen/3323992902/ http://www.flickr.com/photos/thegforcers/6114852991/in/photostream/ http://www.flickr.com/photos/qatarperegrine/5040119481/ http://www.flickr.com/photos/reneeanddolan/6152499201/ http://www.flickr.com/photos/tchelseat/7628965564/ http://www.flickr.com/photos/clappstar/1064543301/ http://www.flickr.com/photos/nycarthur/2482218423/ http://www.flickr.com/photos/oliverlaumann/5525877007/ http://www.websequencediagrams.com/ Credits

    138 Friday, September 14, 2012
  264. http://bit.ly/ poodr-combo 139 Friday, September 14, 2012

  265. Hot off the press http://bit.ly/ poodr-combo 139 Friday, September 14,

    2012
  266. Questions? 140 Friday, September 14, 2012