Report' @text = ['Things are going', 'really, really well.'] end ! def output_report output_start output_head @text.each do |line| output_line(line) end output_end end ! def output_start; end ! def output_head output_line(@title) end ! def output_line(line) raise 'Called abstract method: output_line' end ! def output_end; end end
= 'Monthly Report' @text = ['Things are going', 'really, really well.'] end ! def output_report output_start output_head @text.each do |line| output_line(line) end output_end end ! def output_start; end ! def output_head output_line(@title) end ! def output_line(line) raise 'Called abstract method: output_line' end ! def output_end; end end
user, amount: amount)! end! end # follows OCP by depending on an abstraction! class Purchase! def charge_user!(payment_processor)! payment_processor.charge(user: user, amount: amount)! end! end
print! thing_to_print = case @item! when Text! @item.to_s! when Image! @item.filename! when Document! @item.formatted! end! ! send_to_printer(thing_to_print)! end! end
public void setUrl(String url) {};! public String[] consoleMessages() {};! public String[] alertMessages() {};! public String[] confirmMessages() {};! public String[] promptMessages() {};! }
public void setUrl(String url) {};! public String[] consoleMessages() {};! public String[] alertMessages() {};! public String[] confirmMessages() {};! public String[] promptMessages() {};! } Not all methods are related
setUrl(String url) {};! }! ! public interface HasMessages {! public String[] consoleMessages() {};! public String[] alertMessages() {};! public String[] confirmMessages() {};! public String[] promptMessages() {};! } public class WebPage implements HasUrl, HasMessages {