Reputation: 323
I'm trying to design application in right manner, it should
I found factory pattern helpful so prepeared a UML diagram according to my concern.
Each InvoiceFactoryProvider
can generate PInvoice
or SInvoice
(specific to them). CreatePInvoice()
and CreateSInvoice()
should call load()
and save()
methods.
How to couple load()
with SQLReader class to get each row as PInvoice
object? And save()
with my IDataWriter
interface. Could you provide some example / advice?
Edit:
After reviewing examples of Bridge Pattern, as Atul suggested, I created a class diagram for this problem using it, which looks like this:
Invoice
SQL queries may vary (application may load invoice data from different systems - PollosInvoice
or StarInvoice
) and how they are processed (different implementations).
In this case I decoupled abstraction - Invoice
from its implementation - exporting invoice to certain software (AcmeExporter
or SigmaExporter
). AcmeExporter
and SigmaExport
will set their fields according to specification - date of transaction, payment method, invoice type etc. taken from Invoice's DataTable. ExportInvoice()
will return DataTable
with needed data. InvoiceExporter
is also using two interfaces for encoding and file format.
What do you think about it? What kind of flaws / advantages does it have?
Upvotes: 1
Views: 1645
Reputation: 1774
Currently it looks like you are using Abstract Factory design pattern for the creation of your products (invoices). But point to note is that your load and save method are inside product(invoice) so in that its always better to go with Bridge Design Pattern. Your product will use the implementation of Reader and Writer to load and save the records.
Note: You would be able to use AbstractFactory even with this design pattern.
It will looks something like below... (just an Analogy)
Upvotes: 1