---
title: "Parameterize Method"
type: "refactoring-technique"
slug: "parameterize-method"
url: "http://localhost:3000/en/parameterize-method.md"
category: "Simplifying Method Calls"
description: "Problem: Multiple methods perform similar actions that are different only in their internal values, numbers or operations. Solution: Combine these methods by using a parameter that will pass the necessary special value."
---
# Parameterize Method

> Problem: Multiple methods perform similar actions that are different only in their internal values, numbers or operations. Solution: Combine these methods by using a parameter that will pass the necessary special value.

## Problem

Multiple methods perform similar actions that are different only in their internal values, numbers or operations.

## Solution

Combine these methods by using a parameter that will pass the necessary special value.

## Why Refactor

If you have similar methods, you probably have duplicate code, with all the consequences that this entails.

What’s more, if you need to add yet another version of this functionality, you will have to create yet another method. Instead, you could simply run the existing method with a different parameter.

## How to Refactor

1. Create a new method with a parameter and move it to the code that’s the same for all classes, by applying [Extract Method](/extract-method). Note that sometimes only a certain part of methods is actually the same. In this case, refactoring consists of extracting only the same part to a new method.
2. In the code of the new method, replace the special/differing value with a parameter.
3. For each old method, find the places where it’s called, replacing these calls with calls to the new method that include a parameter. Then delete the old method.
## Relations

**Similar techniques**

- [Extract Method](/en/extract-method.md)
- [Form Template Method](/en/form-template-method.md)

**Opposite refactorings**

- [Replace Parameter with Explicit Methods](/en/replace-parameter-with-explicit-methods.md)

**Eliminates smells**

- [Duplicate Code](/en/smells/duplicate-code.md)

