|Before we do any refactoring we
need to run the unit tests just to be sure we are at 100%. We will rely on the judgment of the unit tests to tell
us if we have made a mistake while refactoring.
What we want to do here is make
the code more self explanatory. We will change the parameter to the setInputBits()
method from aBitMask to theInputBits.
We can create a method inputs(). We can use the inputs() method in both read()
and write(). We can create a method outputs()
to further simplify write(). We can also create a method outputBits() to explain what ~inputBits
means to us. And last we should make the write() method synchronized
Between each change we run our unit
tests. Each time we create a new method, each time we change a name. But for the sake of brevity we will just show
you our completed code.