What is Refactoring
Refactoring is the process of changing the source code alterning the internal structure without changing the external behavior of the code.
Before refactoring the code, complete set of unit-test cases are required. After refactoring the small piece of code then run the test suite to make sure that the code is not broken.
Advantages:
- Readability
- Maintainability
- Extendability
Refactoring Techniques:
o Encapsulate Field – force code to access the field with getter and setter methods
o Generalize Type – create more general types to allow for more code sharing
o Extract Method, to turn part of a larger method into a new method. By breaking down code in smaller pieces, it is more easily understandable. This is also applicable to functions.
o Extract Class moves part of the code from an existing class into a new class.
o Move Method or Move Field – move to a more appropriate Class or source file
o Rename Method or Rename Field – changing the name into a new one that better reveals its purpose
o Pull Up – in OOP, move to a superclass
o Push Down – in OOP, move to a subclass
Martin Fowler explains the refactoring techniques with the diagrams and is really good.
Refactoring Techniques by Martin Fowler
Monday, 10 May 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment