• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Refactor this

 
santosh kulkarni
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I would like the expert opinion over here on making this piece of code less smelly.



It is working code so while loop exits properly on some condition
It is basically processing a screen line by line and populating objects
based on the information on the current line.The methods on the summaryPageDetails return false if the line does not match the regular expression

[EJFH: Added CODE tags to preserve formatting ]
[ November 29, 2005: Message edited by: Ernest Friedman-Hill ]
 
Rick Goldstein
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If all the checks to see if a match is found are performed on the summaryPageDetails object, then I'd move the entire contents of the loop into a method on that class.

Then, make each method into a class of its own with a common method call, like public boolean doesRowMatch(...), with whatever arguments are appropriate. Loop through a collection of instances of these classes, calling doesRowMatch() on each instance until one of them matches. You can even make these processor into inner classes so they have access to common data of the caller.

Does that make sense?

Rick
[ November 29, 2005: Message edited by: Rick Goldstein ]
 
santosh kulkarni
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rick, Thanks for the reply
I was kind of thinking along those lines but your explanation made it very clear. It will need a little more work though. SummaryPageDetails is already an inner class!
if the file becomes huge i'll do some more surgery
Santosh
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm seeing the code-smell of repeating the block, and the 'matchFound' being easily eliminated:

Step 1:


use a shortcut-OR:


if all blocks can be combined this way, we don't need the 'continue' any longer:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic