File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Looking for a Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Looking for a Pattern" Watch "Looking for a Pattern" New topic
Author

Looking for a Pattern

Marco K Paul
Greenhorn

Joined: Jun 16, 2005
Posts: 7
Hello,

I am converting some legacy code and I found a switch statement that contains about 15 diffent switch options based on different documents. then, based on the doc type, a huge chunk of code runs, which varies on the doc type. I'm looking over this and trying to think if there is any design patterns that I can apply. Is there any patterns that help simply huge if..else and switch statement constructs?

Thanks
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
take a look at Strategy Pattern


java amateur
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1007
    
    3
I think this calls for just plain old subclassing/polymorphism.

There may indeed be a reason to go with a Strategy, but just putting the processing for each doc type in its own class is a good first step.
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
Seems like this refactoring would do the trick.
http://www.refactoring.com/catalog/replaceConditionalWithPolymorphism.html

Here is the link to the whole catalog of refactorings:
http://www.refactoring.com/catalog/index.html


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looking for a Pattern