Replace Parameter with Explicit Methods

You have a method that runs different code depending on the values of an enumerated parameter.

Create a separate method for each value of the parameter.

	void setValue (String name, int value) {
		if (name.equals("height")) {
			_height = value;
			return;
		}
		if (name.equals("width")) {
			_width = value;
			return;
		}
		Assert.shouldNeverReachHere();
	}

	void setHeight(int arg) {
		_height = arg;
	}
	void setWidth (int arg) {
		_width = arg;
	}

For more information see page 285 of Refactoring

| Refactoring Home | | Alphabetical List |