Design Pattern to replace a method with many parameters
builder, design-patterns, java
Solution
If I face a method that has too many parameters I do the following steps usually:
I try to identify an entity these parameters are related to and check if Preserve Whole Object refactoring can be used.
You are getting several values from an object and passing these values as parameters in a method call. Send the whole object instead.
If all these parameters are independent and I want to increase number of parameters I use another one common solution - Introduce Parameter Object refactoring.
You have a group of parameters that naturally go together. Replace them with an object.
In order to build that `object` other techniques and patterns can be used (e.g. Builder, Method chaining, Fluent interfaces).
Problem
Java 1.6 I have a method with many parameters. This is not a constructor but a normal method. ``` class A { public void m (int a, int b, boolean c, List<>...) { } } ``` How to replace a method to a better form ? As I understand the `Builder` design pattern is for contructors.