Long Parameter List
A method has more than one or two parameters.
You might be trying to minimize coupling between objects. Instead of the called object being aware of relationships between classes, you let the caller locate everything; then the method concentrates on what it is being asked to do with the pieces.
Or a programmer generalizes the routine to deal with multiple variations by creating a general algorithm and a lot of control parameters.
What to Do
If the parameter value can be obtained from another object this one already knows, Replace Parameter with Method.
If the parameters come from a single object, try Preserve Whole Object.
If the data is not from one logical object, you still might group them via Introduce Parameter Object.
Improves communication. May expose duplication. Often reduces size.
Sometimes, you want to avoid a dependency between two classes. For example, the caller may have the dependency, but you don't want to propagate it. Ensure that your changes don't upset this balance.
Sometimes the parameters have no meaningful grouping—they don't go together.
This is one of those places where a smell doesn't guarantee a problem. You might smell a Long Parameter List but decide it's right for the situation at hand.
Long Parameter List.
Consider these methods declared in the Java libraries:
public void paintComponent(Graphics gr, Component renderer, Container parent, int x, int y, int width, int height, Boolean shouldValidate)
public Boolean drawImage(Image image, int x1Dest, int y1Dest, int x2Dest, int y2Dest, int x1Source, int y1Source, int x2Source, int y2Source, Color color, ImageObserver obs)
public void setRangeProperties( int newValue, int newExtent, int newMin, int newMax, boolean isAdjusting)
public static int showConfirmDialog(Component parent, Object message, String title, int optionType, int messageType, Icon icon)
For each declaration above, is there any cluster of parameters you might reasonably group into a new object?
Why might those signatures have so many parameters?
Look back at the JTable declaration (EXERCISE-5, earlier in the chapter). Do you see any clusters of parameters there?