# The class, Printer takes a generic parser. It doesn't depend on the
# low-level details of PdfFormatter or HtmlFormatter classes.
class Printer
def initialize(data, formatter)
@data = data
@formatter = formatter
end
def print(formatter)
formatter.format(@data)
end
end
class PdfFormatter
def format(data)
# format data to Pdf logic
end
end
class HtmlFormatter
def format(data)
# format data to Html logic
end
end