Given web service method:
public void FindSomeEntities(int? Id, string param1, int? param2, ...)
Refactored:
public void FindSomeEntities(SelectionParameters selectionParameters)
class SelectionParameters
{
public int? Id;
public string param1;
public int? param2
...
}
Pros:
- too many parameters in original web service method reduced to the
only one - if there is need to change we won’t have to change the
interface of the method – only the definition of SelectionParameters
Cons:
- class SelectionParameters hasn’t any business value – it’s used only
as helper class and it’s used in a single method. As a result we’ll
have many methods with 1 parameters and plenty of one-off classes - Actually the interface IS changed, we just push these changes a bit
deeper.
This refactoring is called Introduce Parameter Object. It is likely to be a good idea if the parameters are naturally related to each other, and especially if they’re frequently used together as parameter lists to multiple methods.