class ReportGenerator def initialize @report = "" end def output prepare_header prepare_body prepare_footer @report end def prepare_header raise "Prepare header should be implemented" end def prepare_body raise "Prepare body should be implemented" end def prepare_footer raise "Prepare footer should be implemented" end end class TxtReportGenerator < ReportGenerator def prepare_header @report << "Txt Report header \n" end def prepare_body @report << "body \n" end def prepare_footer @report << "footer \n" end end class PdfReportGenerator < ReportGenerator def prepare_header @report << "Pdf Report header \n" end def prepare_body @report << "some encoded body \n" end def prepare_footer @report << "encoded footer \n" end end txt = TxtReportGenerator.new pdf = PdfReportGenerator.new puts txt.output puts pdf.output
Saturday, August 23, 2014
Template method pattern ruby
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment