When it is necessory to do code refactoring?
If your application degrades the performance , you require code refactoring.
Find following areas/cases where you need to have code refactoring :
1) Long methods with long parameter lists.
2) Message list chains
3) Data clumps
4) Redundent code
5) Divergent change
what are the basic principles of code refactoring?
1) Seperation of Concerns (SOC)
2) Dependency Inversion
3) Single Responsibilty Principle (SRP)
4) Inversion of control (IOC)
What are the things which should be avoided?
1) Avoid writing long methods. Write small piece of code always and it should be self explainatory.
2) Write the comments in the code to clarify why this code is required to be there and not for what is explained in the code.
3) Avoid duplicate code in the application . If you want to have same code again and again then put that code in the common class.
4) Class should not contain long parameter lists. Pass necessory parameters only.
5) Class should not have too many instance variables. It degrades the performance of your application.
6) Always use small data objects.
7) Any change to handle variation should be in single class.
8) Use methods in the class more efficiently.
What are the refactoring techniques?
1) Exact method : Turn the fragment in to method whose name explains purpose of the method.
2) Replace Temp with Query : Replace the expression into the method. Replace all references of temp in to expression. Then the new method can be used in other methods.
3) Introduce parameter objects : Group of parameters can be replaced with proper object.
4) Pull down method
5) Replace parameters with method.
6) Replace type code with class / subclass.
7) Replace type code with state object.
No responses found. Be the first to comment...