This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Looking for a Pattern

 
Marco K Paul
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
take a look at Strategy Pattern
 
Ryan McGuire
Ranch Hand
Posts: 1048
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 862
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic