Long parameter list smell
(New page: 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 pr...) |
Brett Ward (Talk | contribs) m (Adding other not mentioned common refactorings from Fowler) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 5: | Line 5: | ||
== Refactoring == | == Refactoring == | ||
− | 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 [[Replace Parameter with Explicit Methods]] | + | 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 == | ||
+ | * [[Replace Parameter with Explicit Methods]] | ||
+ | * [[Introduce Parameter Object]] | ||
+ | * [[Code smells]] | ||
+ | |||
+ | {{Template:CodeSmells}} | ||
+ | |||
+ | [[Category:Code smells]] |
Latest revision as of 10:25, 14 October 2009
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.
Refactoring
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