Remove Setting Method
A field should be set at creation time and never altered.
Remove any setting method for that field.
For more inforamtion see page 300 of Refactoring
Paul Haahr kindly pointed out to me that I've not been accurate with the use of
final in this refactoring. The point that I missed is that you can't use a final field if the initialization is done in a separate method to the constructor. This the example at the bottom of page 301 (that uses
initialize(id)) just does not compile. (My apologies for not testing that fragment, some do slip through the net....) If you want to use a separate method, you can't make the field final
This also means that the mechanics is incorrect. Making the field final should be the last step not the first, and can only be done if it's possible.
- Paul Haahr