views:

35

answers:

1

Hello,

What's the best design pattern to use for an HTTP Request Dispatcher that has to do a "GET" or a "POST", return an output stream, parse the output stream, and then display the parsed results on an interface?

Currently, I have an HttpRequestDispatcher.java in which a UI Class is defined in its constructor, and in the threaded run() method, the results are sent to UIClass.requestSucceeded or UIClass.requestFailed, where the stream is then parsed and the results displayed.

The problem with this is I really want a separation of concerns between the interface, the parser, and the dispatcher. This way, in the future, I can really re-use the dispatcher with many other classes...Right now, I have to have one HttpRequestDispatcher for every "Screen"...

Would appreciate any advice, thanks!

+1  A: 

First of all you should dispatch already parsed thing to the view. Your view should not control the parsing stuff/logic.

Now the flow should go something like this,

Parse -> Dispatch -> Present

Here I feel that you are using your dispatcher as a controller, so you might want to make it a singleton kinda thing, and build factory of parsers. Then your dispatcher should decide what parser is required based on some parameter, and also should determine an appropriate view to dispatch the parsed thing.

Adeel Ansari
Nice suggestion, I'm going to sketch it out on paper and see how it looks. Thanks!
behrk2