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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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