Self Encapsulate Field

You are accessing a field directly, but the coupling to the field is becoming awkward.

Create getting and setting methods for the field and use only those to access the field.


	private int _low, _high;

	boolean includes (int arg) {

		return arg >= _low && arg <= _high;

	}


	private int _low, _high;

	boolean includes (int arg) {

		return arg >= getLow() && arg <= getHigh();

	}

	int getLow() {return _low;}

	int getHigh() {return _high;}

For more information see page 171 of Refactoring

| Refactoring Home | | Alphabetical List |