Home  /  Questions  /  Question

50   50
Feb 16, 2013

Factory or Strategy or Builder Pattern

I've got an application that creates and sends packets. A packet consists of one or more document objects. e.g.

Packet1 = [ DocA, DocB, DocB, DocB ]
Packet2 = [ DocB, DocB, DocC ]
Packet3 = [ DocC, DocB, DocA ]

Document objects vary in the number and type of input parameters used to query a database; they return unique datasets to fill specific document fields.

Both packet and document types are expected to grow.

Packets use different transport protocols. One might send() via fax server, another SMTP, FTP, save to PDF file, etc.

I think the strategy pattern could be utilized to isolate variances in the send() methods.

I'm wondering if the factory or builder pattern could be applied here to create the documents and then packets? My goal is make the application extensible in regards to adding new packet and document types. Any suggestions or insight would be appreciated. Thanks.

50   50
Feb 19, 2013
I ended up using a factory for both documents and packets. Strategy pattern was used to handle the different transport protocols for the packet object.

The concrete classes are now only stubbed out with log messages but so far the solution looks extensible.