Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question is mostly about the best way to approach this problem. Any input is appreciated.

The Problem

In my application i need to send some data to a number of different destinations (we will call them receivers from now on) using different protocols (http post, ftp, soap services). Each of the different receivers respond differently and some processing needs to be done on each response to work out what happened. This response processing can become quite complex.

My application also needs to do take different actions based on the receiver.

My Solution

My plan is to create a separate class for each receiver that implements an interface and use Factory design pattern to decide which class to load based on the receiver. Each receiver has a unique name (which is stored in the database for other reasons) which i plan to use to decide which receiver to load. I'll pass this to the factory constructor.

Currently i plan to have my interface implement these methods

  • prepareData()
  • sendData()
  • handleResult()

I'd also like a wrapper for these function such as process() which would just return a boolean based on wether the send sent. I'm not sure where i would fit this in though.


share|improve this question
I tried to see other patterns /ideas, but, the Factory Method pattern you mention, sounds like the best. – umlcat Mar 9 '12 at 16:08

If you're thinking that your interface needs to do three different things (prepare, send, and handle), think some more about cohesion.

That is, you need something that knows how to prepare data differently for different receivers. This is a task in and of itself--so separate it from the other tasks into a series of items implementing an DataFactory interface (a la Factory Method pattern).

Again, the method for sending the data varies, encapsulate that into DataTransport classes (Strategy pattern?) Along the same lines, ResultHandler classes to handle each type of the result.

This way each class does exactly one thing, and can be tested and adjusted in its own right, without affecting anything else.

Think about it any way.

share|improve this answer

You can also check out the Template Method Pattern, this will help you encapsulate the process/algorithm.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.