G van Damn

G van Damn

  • NA
  • 4
  • 0

Preventing duplicate code in different for loops

Jan 3 2011 12:42 PM

I've got a class, let's say a "mutual fund portfolio". It's got 3 methods that calculate 3 different numbers each using a for-loop. Most of the steps in the 3 different methods are exactly the same, except for 1 or 2 steps.
Is there a smarter way to prevent duplicate code than just writing 1 base method and using a case statement for the 3 different numbers to be calculated?
(I hope the description is clear enough.)

Answers (3)