Skip to content

Instantly share code, notes, and snippets.

@marzoukali
Created July 1, 2017 23:49
Show Gist options
  • Save marzoukali/b2b4d901f7316d54865542e0f5d1deae to your computer and use it in GitHub Desktop.
Save marzoukali/b2b4d901f7316d54865542e0f5d1deae to your computer and use it in GitHub Desktop.
public interface IInvoiceWriter
{
void Write(Invoice invoice);
}
public class InvoiceWriter : IInvoiceWriter
{
private readonly IPrinter _printer;
private readonly IPageLayout _layout;
public InvoiceWriter(
IPrinter printer,
IPageLayout layout)
{
_printer = printer;
_layout = layout;
}
public void Write(Invoice invoice)
{
_printer.SetPageLayout(_layout);
if (invoice.IsOverdue)
_printer.SetInkColor("Red");
_printer.WriteLine("Invoice ID: " + invoice.Id);
// Remaining print statements would go here
}
}
public class PrintInvoiceCommand
{
private readonly IDatabase _database;
private readonly IInvoiceWriter _writer;
public PrintInvoiceCommand(
IDatabase database,
IInvoiceWriter writer)
{
_database = database;
_writer = writer;
}
public void Execute(int invoiceId)
{
var invoice = _database.GetInvoice(invoiceId);
_writer.Write(invoice);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment