Created
July 1, 2017 23:49
-
-
Save marzoukali/b2b4d901f7316d54865542e0f5d1deae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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