Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Mutators

A mutator  is a method that can modify an object. In the simplest case, a mutator just assigns a new value to one of the fields. In general, a mutator performs some computation and modifies any number of fields.

The setReal and setImag methods defined in Program gif are mutators. Program gif defines three more mutators for the Complex class, setR, setTheta, and assign. All three of these assign new values to the real and imag fields, as appropriate.

   program56536
Program: Complex class mutator methods.


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.