File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Looking for a Pattern

Marco K Paul

Joined: Jun 16, 2005
Posts: 7

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?

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: 1044
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: 862
Seems like this refactoring would do the trick.

Here is the link to the whole catalog of refactorings: - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
I agree. Here's the link:
subject: Looking for a Pattern
jQuery in Action, 3rd edition