Extracting the bar
calculation into a separate object, which doesn't know about Foo
, allows us to test this code in more isolation and to easily change it in the future, because of its reduced context.
Last active
August 29, 2015 14:07
-
-
Save valo/b318c37dafebcf4424cf to your computer and use it in GitHub Desktop.
This file contains 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
class BarCalculation | |
def initialize(input1, input2) | |
@input1 = input1 | |
@input2 = input2 | |
end | |
def calculate | |
# ..... the same bad code | |
end | |
private | |
attr_reader :input1, :input2 | |
end |
This file contains 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
class BetterFoo | |
private | |
def bar | |
new BarCalculator(intpu1, input2).calculate | |
end | |
end |
This file contains 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
class Foo | |
private | |
def bar | |
# .... some really bad code @#$@#$ | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment