Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Refactoringbeginner

Parameter Object

Share

Replace long parameter lists with parameter objects

Works with OpenClaude

You are a refactoring expert. The user wants to replace long parameter lists with parameter objects to improve code readability and maintainability.

What to check first

  • Count the number of parameters in your function signature — if it's more than 3-4, it's a candidate for refactoring
  • Identify which parameters are frequently passed together across multiple function calls
  • Check if parameters share logical grouping (e.g., coordinates, user details, configuration settings)

Steps

  1. Identify the function with a long parameter list that you want to refactor
  2. Create a new object type (class, interface, or type alias) to hold the related parameters
  3. Group logically related parameters into the new object — for example, x, y, z become a Point object with x, y, z properties
  4. Replace the individual parameters in the function signature with a single parameter of the new object type
  5. Update all function calls to pass an object instead of individual arguments
  6. Update the function body to access properties from the parameter object (e.g., change x to params.x)
  7. Add default values to the object type if some parameters are optional
  8. Consider adding a constructor or factory function for common parameter combinations

Code

// BEFORE: Long parameter list
function createUser(firstName, lastName, email, age, address, city, zipCode, country, phone) {
  const user = {
    firstName,
    lastName,
    email,
    age,
    address,
    city,
    zipCode,
    country,
    phone
  };
  validateEmail(email);
  return user;
}

createUser("Jane", "Doe", "jane@example.com", 30, "123 Main St", "Boston", "02101", "USA", "555-1234");

// AFTER: Parameter object
class UserParams {
  constructor(firstName, lastName, email, age, address, city, zipCode, country, phone = null) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.email = email;
    this.age = age;
    this.address = address;
    this.city = city;
    this.zipCode = zipCode;
    this.country = country;
    this.phone = phone;
  }
}

function createUser(params) {
  const user = {
    firstName: params.firstName,
    lastName: params.lastName,
    email: params.email,
    age: params.age,
    address: params.address,
    city: params.city,
    zipCode: params.zipCode,
    country: params.country,
    phone: params.phone
  };
  validateEmail(params.email);
  return user;
}

// Or using TypeScript/modern object syntax:
function createUser({ firstName, lastName, email, age, address, city, zipCode, country, phone = null }) {
  const user = { firstName, lastName, email, age, address, city, zipCode, country

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryRefactoring
Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
refactoringparametersclean-code

Install command:

curl -o ~/.claude/skills/parameter-object.md https://claude-skills-hub.vercel.app/skills/refactoring/parameter-object.md

Related Refactoring Skills

Other Claude Code skills in the same category — free to download.

Want a Refactoring skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.