Refactoring Remove Setting Method
The value of a field should be set only when it is created, and not change at any time after that.
So remove methods that set the field's value.
You want to prevent any changes to the value of a field.
How to Refactor
- The value of a field should be changeable only in the constructor. If the constructor does not contain a parameter for setting the value, add one.
- Find all setter calls.
- If a setter call is located right after a call for the constructor of the current class, move its argument to the constructor call and remove the setter.
- Replace setter calls in the constructor with direct access to the field.
- Delete the setter.
Tired of reading?
No wonder, there are 7 hours worth of the text on this website.
Try our interactive course on refactoring. It offers less boring approach to learning new stuff.Let's see...