mutator method
All > Technology > Programming > Java
- A method specifically designed to allow controlled modification of a
privateattribute of a class. By convention, we name mutators with asetprefix followed by the name of the attribute being modified. For instance, the mutator for an attribute namedspeedwould besetSpeed. By making an attribute private, we prevent objects of other classes from altering its value other than through its mutator. The mutator is able to check the value being used to modify the attribute and reject the modification if necessary. In addition, modification of one attribute might require others to be modified in order to keep the object in a consistent state. A mutator method can undertake this role. Mutators are used both to grant safe access to the value of a private attribute and to protect attributes from modification by objects of other classes. The latter goal is achieved by choosing an appropriate visibility for the mutator.
David J. Barnes - Cite This Source - This Definition - accessor method, Attribute, State