Doing It the Hard Way

While the refactoring sequence in the first scenario produces an extremely efficient redesign of existing code, the operations themselves are highly repetitive. Unless you have an unending supply of unpaid, volunteer programmers, you will want to use automation tools, such as a refactoring-capable IDE. In contrast, let's look at the painful steps needed to perform the same necessary operations manually:

Stage 1. Manually create an interface to be implemented by the AccessRightsTable, as well as by the manually created MutableAccessRightsTable and ImmutableAccessRightsTable. Manually create all methods in the two new classes and make them use the delegate field in the method body. Manually wrap methods in MutableAccessRightsTable with the synchronized{} block. After having spent, say, half an hour or more at that, you would take a coffee break (another 10-15 minutes) and come back with a clear mind to tackle the second stage—involving work so boring, you do not even want to think about it.

Stage 2. Find all usage of the AccessRightsTable class in your project (field types, variable types, parameter types, method return types). For each usage, decide whether to manually switch to the AbstractAccessRightsTable interface instead of the class. Find all usages of the AccessRightsTable constructor in your project. Analyze the contextual role of the variable or field holding an instance of AccessRightsTable and try to foresee possible future usages of each particular instance, to either leave it as-is or wrap it up with the MutableAccessRightsTable or ImmutableAccessRightsTable constructor calls.

Depending on the size of your project, these steps might take you anywhere from one to dozens of man hours to complete. By contrast, the right automation tool gets it done in seven minutes.

—E.B., M.S., and A.O.

Back to Article