Martin Fowler on Refactoring
The following quote comes from “Refactoring” by Martin Fowler, page 67. In this section of the book, he is talking about refactoring vs trying to design everything up front.
——————————————————————————–
With refactoring the emphasis changes. You still do upfront design, but now you don’t try to find the solution. Instead all you want is a reasonable solution. You know that as you build the solution, as you understand more about the problem, you realise that the best solution is different from the one you originally came up with. With refactoring this is not a problem, for it no longer is expensive to make the changes.
An important result of this change in emphasis is a greater movement toward simplicity of design. Before I used refactoring, I always looked for flexible solutions. With any requirement I would wonder how that requirement would change during the life of the system. Because design changes were expensive, I would look to build a design that would stand up to the changes I could foresee. The problem with building a flexible solution is that flexibility costs. Flexible solutions are more complex than simple ones. The resulting software is more difficult to maintain in general, although it is easier to flex in the direction I had in mind. Even there, however, you have to understand how to flex the design. For one or two aspects this is no big deal, but changes occur throughout the system. Building flexibility in all these places makes the overall system a lot more complex and expensive to maintain. The big frustration, of course , is that all this flexibility is not needed. Sum of it is, but it’s impossible to predict which pieces those are. To gain flexibility, you are forced to put in a lot more flexibility that you actually need.
With refactoring you approach the risks of change differently. You still think about potential changes, you still consider flexible solutions. But instead of implementing these flexible solutions, you ask yourself, “How difficult is it going to be to refactor a simple solutions into a the flexible solution?” If, as happens most of the time, the asnwer is “pretty easy,” then you just implement the simple solution.