Long parameter list smell

From CSSEMediaWiki
Jump to: navigation, search

The Long parameter list smell means you have a method that is requiring too many parameters to be passed in. In Refactoring Martin Fowler 1999 mentions the fact that in the past programmers were taught to pass everything a method required as a parameter because global data was considered evil and painful. Object oriented programming changed this because if there is a piece of data you need but don't have, then you can always ask another object to get that piece of data for you.

The important concept that arises out of this is that with objects you don't pass everything the method needs. Instead you "pass enough so that the method can get to everything it needs". This means that generally parameter lists are shorter in Object Oriented programs.


To beat the Long parameter list smell, there are a few things you can do to refactor it out of your code. When you are in the situation where you can get the data required for a parameter by requesting it from an object you already know about, the refactoring technique will be most suitable.

The Preserve Whole Object technique is useful if you wish to replace a whole lot of data taken from an object with the object itself.

See also

Personal tools