Concept of Refactoring

If you read the XP life cycle, one of the things after we implement the task is code refactoring. Refactoring is the process of changing the software in such a way that it does not change the behavior of the code but on the other hand improves the internal structure. No code can be perfect with architecture, coding conventions, and high reusability at the first level itself. Normally it improves over time. It helps developers to implement the necessary solutions today and improve / make the code better tomorrow. Refactoring is the process of changing the system to improve the internal structure without changing what the system does. Below are the three major activities performed during refactoring.
Simplify complex code
XP is all about light-weight and simplicity. This holds true not only for a process but also for coding. When you see a code can be simplified, discuss it with your developing partner and implement it. For instance, shown below is code which was further simplified into one equation:
Simplify codeMove similar operations into reusable code. If we have similar operations, move them to one reusable code. For instance, in the class below, we have various sort functions which sort by phone, code, name, and date. We can combine them into one function called sort and make it simple.
Reusable codeRemove duplicates and redundancy
When a project has constrained timelines, it’s very much possible that the project can have lot of duplications. So when developers have finished their tasks, they can review for these kinds of duplications. For example, the below figure ‘Remove duplication’ shows how the phone number duplication is removed from the customer table. The customer table has repetitive fields like mobile number, land line, and office number. In abstract terms, these represent telephone numbers. So we split the customer table into two tables, customer and customerphone, and build a relationship between them.
Remove duplicationShown below another scenario where we have an invoice class which has two methods GenerateInvNo and CreateInvNo and they do the same thing, generate unique invoice numbers. We can refactor / improve the code by combining these two methods into one.
Code duplicationNo code is perfect, it has to be made perfect.
What is a feature in Feature Driven Development? Feature is a process which adds value to the end customer and it can be planned. In short, it has two characteristics:

  • We can plan and schedule a feature.
  • It should be something that delivers value to the end user.

Feature

Tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.