Parameterize Method

You parameterize a method when two methods do substantially the same thing, and the only difference is something that could be a parameter. MartinFowler gives the example of fivePercentRaise and tenPercentRaise methods.

Change:

fivePercentRaise = salary + (salary * 0.05)

and

tenPercentRaise = salary + (salary * 0.10)

to

salary = salary + (salary * increaseFactor)

This is explained much better on page 283 of the RefactoringBook.


CategoryRefactoring


EditText of this page (last edited March 14, 2008) or FindPage with title or text search