Skip to content

Instantly share code, notes, and snippets.

@sgharms
Last active January 3, 2016 12:19
Show Gist options
  • Save sgharms/8461970 to your computer and use it in GitHub Desktop.
Save sgharms/8461970 to your computer and use it in GitHub Desktop.
class Sandwich
end
class GrilledCheeseMaker
def initialize(bottom_substrate, top_substrate, cheese_type, cook_type)
@bottom_substrate = bottom_substrate
@top_substrate = top_substrate
@cheese_type = cheese_type
@cook_type = cook_type
make_sandwich!
end
def make_sandwich!
puts "Getting #{@bottom_substrate} of bread"
puts "Getting #{@top_substrate} of bread"
puts "Getting some #{@cheese_type}"
puts "Putting #{@cheese_type} on #{@bottom_substrate}"
puts "Putting #{@top_substrate} on half-completed cold sandwich"
puts "Putting a #{@cook_type} on the sandwich"
end
end
GrilledCheeseMaker.new('wheat', 'wheat', 'gruyere', 'wicked scorch')
class Sandwich
end
class GrilledCheeseMaker
def initialize(bottom_substrate, top_substrate, cheese_type, cook_type)
@bottom_substrate = bottom_substrate
@top_substrate = top_substrate
@cheese_type = cheese_type
@cook_type = cook_type
make_sandwich!
end
def make_sandwich!
get_items
arrange_items
cook_sandwich
end
private
def get_items
puts "Getting #{@bottom_substrate} of bread"
puts "Getting #{@top_substrate} of bread"
puts "Getting some #{@cheese_type}"
end
def arrange_items
puts "Putting #{@cheese_type} on #{@bottom_substrate}"
puts "Putting #{@top_substrate} on half-completed cold sandwich"
end
def cook_sandwich
puts "Putting a #{@cook_type} on the sandwich"
end
end
GrilledCheeseMaker.new('wheat', 'wheat', 'gruyere', 'wicked scorch')
=begin rdoc
## Why is this better?
* We've provided 3 debug domains by doing this (is the issue in item fetching,
preparation, or cooking?)
* By doing so these methods can easily be moved (Refactoring: Move Method) and
re-homed onto the `Sandwich` class
* Is this fully-factored into proper objects? **NO**. But we are offering a
way of attacking complexity thaty easily segueywas into discussions around:
* inversion of control
* dependency injection
* means for scaling to complexity
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment