Created
November 2, 2010 11:25
-
-
Save cheeyeo/659502 to your computer and use it in GitHub Desktop.
Report class refactored to use Template pattern
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
class Report | |
def initialize | |
@title = 'My Report' | |
@text = ['Lorem’, ‘Ipsum'] | |
end | |
end | |
def output_report | |
output_start | |
output_head | |
output_body_start | |
output_body | |
output_body_end | |
output_end | |
end | |
def output_body | |
@text.each do |line| | |
output_line(line) | |
end | |
end | |
def output_start raise 'Called abstract method: output_start' | |
end | |
def output_head raise 'Called abstract method: output_head' | |
end | |
def output_body_start raise 'Called abstract method: output_body_start' | |
end | |
def output_line(line) raise 'Called abstract method: output_line' | |
end | |
def output_body_end raise 'Called abstract method: output_body_end' | |
end | |
def output_end raise 'Called abstract method: output_end' | |
end | |
end # end Report Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like the Report class is ended just after the initialize method. I assume that all of the methods should be inside the Report class?