Code Refactoring – Part 2

Move Method Refactoring:  Move method can be apply with help of below steps

1) Scan the code

2) Check the superclass/subclass

3) Create the new method and rename if necessary

4) Copy the code

5) Replace the original call

Code smell for move method are

>> Feature envy: Method is more related to another class than the class in which it is defined.

>> Inappropriate intimacy: Two classes are not doing more than just calling each others properties and method to server the purpose, so it is better to apply the move method refactoring by looking into the code.

>> Shotgun surgery: This we can notice when we apply the code changes, for example when we make the changes in class A then we need to make some changes in class B and then in class C and so on.

Extract Class Refactoring: As we see that as the project is growing class is also growing with the new properties and methods, even though those are related to that class but can be split into another class and then use in the parent class.

Code smell: large class

Example: Customer class with Address.

Inline Class Refactoring: This refactoring is apply only when we lets say when we have applied the move method, move fields and move class refactoring on a class and there hardly something left, so it will be better to move that content into the another class which we see more related to it.





#code-refactoring, #code-smell, #move-method, #move-method-refactoring, #refactoring