Introduce Parameter Object

You have a group of parameters that naturally go together.

Replace them with an object.

image/svg+xml Customer amountInvoicedIn (start : Date, end : Date)amountReceivedIn (start : Date, end : Date)amountOverdueIn (start : Date, end : Date) Customer amountInvoicedIn (: DateRange)amountReceivedIn (: DateRange)amountOverdueIn (: DateRange)

Naming: This refactoring is sometimes called "extract parameter object".


Dealing with a chain of calls

Ralph Johnson pointed out to me that a common case isn't clear in the Refactoring book. This case is when you have a bunch of methods that call each other, all of which have a clump of parameters that need this refactoring. In this case you don't want to apply Introduce Parameter Object because it would lead to lots of new objects when you only want to have one object that's passed around.

The approach to use is to start with the head of the call chain and apply Introduce Parameter Object there. Then apply Preserve Whole Object to the other methods.