Encapsulation provides a way of hiding members of a class, and restricting their access, so that potentially an object's members can only be manipulated by the object itself. Encapsulation is one of the keystones of object-oriented development.
First we will need a Java project so that we can encapsulate some fields within a class. We will use the same project from the earlier recipe, Rename refactoring, and so ensure that you have the project open from the end of that recipe. If you have not followed that recipe, the project is available from the code download bundle under the MoveRefactor
folder in Chapter 3
. When the Projects explorer shows the Refactoring
project, expand the Refactoring
node if not yet expanded.