introduce-parameter-object
Replace a recurring group of parameters with a single data object.
SKILL.mdskills/code-quality/introduce-parameter-object/SKILL.md
GitHubIntroduce Parameter Object
When several parameters always travel together across multiple methods, group them into a single object. This reduces signature size, prevents inconsistency, and opens the door for domain logic on the new object.
When to Use
- Two or more parameters always appear together in method signatures
- Methods share the same "cluster" of parameters
- The parameter group represents a coherent domain concept (e.g., date range, coordinates, pagination)
How to Apply
- Create a value object/data class to hold the parameter group
- Add the new class as a parameter to one method
- Remove the individual parameters now covered by the object
- Migrate remaining methods to use the new object
- Look for behaviour that belongs on the new object and move it there
- Run tests
Example
// Before
function readingsOutsideRange(readings: number[], min: number, max: number) { … }
function countInRange(data: number[], min: number, max: number) { … }
// After
class NumberRange {
constructor(readonly min: number, readonly max: number) {}
includes(n: number) { return n >= this.min && n <= this.max; }
}
function readingsOutsideRange(readings: number[], range: NumberRange) { … }
function countInRange(data: number[], range: NumberRange) { … }