What is Refactoring? Let me give my own definition:
Refactoring is a disciplined technique for improving software internally without changing its external behaviour.
Or, as Fowler defines it in his book:
“The process of changing a software system in such a way that it does not alter the external behaviour of the code yet improves its internal structure”
Or, from Fowler’s www.refactoring.com website:
“Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.”
For example, if I rename a variable within my code, I have (hopefully) chosen a more meaningful name, and thus the code has improved internally, but its external behaviour has (hopefully!) remained identical.
Another example. I have two classes which I notice share a degree of common functionality, so I create a parent class which contains the common functionality, and then in each of the two original classes I simply keep the functionality which is different. I have improved the software internally because I have reduced duplication and structured the code in a way that shows the relatedness between two previously separate classes, but yet without changing the external behaviour. The software should work exactly the same after the change as before the change.
Refactoring is a disciplined technique, that is, it is done systematically and according to a well-defined cycle of small step, test, small step, test, build.
So, to unpack the definition a little, refactoring is three essential things:
1. a disciplined technique
2. for improving software internally
3. without changing its external behaviour
See my book The Refactoring Workout for more on refactoring.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment