andela-amagana
11/23/2017 - 1:35 PM

Dependency inversion fail

# Dependency inversion violation
# Here we see print_pdf and print_html
# depend on the formatter classes intanciated in them
class Printer
  def initialize(data)
    @data = data
  end

  def print_pdf
    PdfFormatter.new.format(@data)
  end

  def print_html
    HtmlFormatter.new.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