What is the best approach to solve a factory method problem which has to be an instance?

Posted by Iago on Programmers See other posts from Programmers or by Iago
Published on 2012-11-08T19:38:25Z Indexed on 2012/11/08 23:16 UTC
Read the original article Hit count: 270

Filed under:
|

I have to add new funcionality in a web service legacy project and I'm thinking what is the best approach for a concrete situation.

The web service is simple: It receives a XML file, unmarshalling, generates response's objects, marshalling and finally it sends the response as a XML file. For every XML files received, the web service always responds with the same XML structure.

What I have to do is to generate a different XML file according to the XML received. So I have a controller class which has all marshalling/unmarshalling operations, but this controller class has to be an instance. Depending on XML received I need some marshalling methods or others.

Trying to make few changes on legacy source, what is the best approach? My first approach was to do a factory method pattern with the controller class, but this class has to be an instance.

I want to keep, as far as it goes, this structure:

classController.doMarshalling();

I think this one is a bit smelly:

if(XMLReceived.isTypeOne())
    classController.doMarshallingOne();
else if(XMLReceived.isTypeTwo())
    classController.doMarshallingTwo();
else if(XMLReceived.isTypeThree())
    classController.doMarshallingThree();
else if ...

I hope my question is well understood

© Programmers or respective owner

Related posts about design

Related posts about design-patterns