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. Martin Fowler 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 Refactoring Book.


See original on c2.com