title: Factory Pattern implementation coupled with reading and writing
body: <p>I'm trying to design application in right manner, it should </p>
  
  <ol>
  <li>Read invoice data from SQL Server (2 queries depending on type of
  invoice: sales or purchase) </li>
  <li>Process it (Acme may need less fields than SugarCorp and in different formatting) </li>
  <li>Output txt or csv (that may change in future)</li>
  </ol>
  
  <p>I found factory pattern helpful so prepeared a UML diagram according to my concern. </p>
  
  <p><img src="https://i.imgur.com/vqBVq.png" alt="UML diagram"></p>
  
  <p>Each <code>InvoiceFactoryProvider</code> can generate <code>PInvoice</code> or <code>SInvoice</code> (specific to them). <code>CreatePInvoice()</code> and <code>CreateSInvoice()</code> should call <code>load()</code> and <code>save()</code> methods.</p>
  
  <p>How to couple <code>load()</code> with SQLReader class to get each row as <code>PInvoice</code> object? And <code>save()</code> with my <code>IDataWriter</code> interface. Could you provide some example / advice? </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>After reviewing examples of Bridge Pattern, as Atul suggested, I created a class diagram for this problem using it, which looks like this:</p>
  
  <p><img src="https://i.imgur.com/aX0k7Nr.jpg" alt="UML diagram - Bridge Pattern"></p>
  
  <p><code>Invoice</code> SQL queries may vary (application may load invoice data from different systems - <code>PollosInvoice</code> or <code>StarInvoice</code>) and how they are processed (different implementations).</p>
  
  <p>In this case I decoupled abstraction - <code>Invoice</code> from its implementation - exporting invoice to certain software (<code>AcmeExporter</code> or <code>SigmaExporter</code>). <code>AcmeExporter</code> and <code>SigmaExport</code> will set their fields according to specification - date of transaction, payment method, invoice type etc. taken from Invoice's DataTable. <code>ExportInvoice()</code> will return <code>DataTable</code> with needed data. <code>InvoiceExporter</code> is also using two interfaces for encoding and file format.</p>
  
  <p>What do you think about it? What kind of flaws / advantages does it have? </p>