24 March, 2006

Refactoring

1. Introduction

The process of changing a software system in such away that it does not alter the external behavior of the code, yet improves it’s internal structure.
- Martin Fowler
Refactoring is the process of taking an object design and rearranging it in various ways to make the design more flexible and/or reusable. There are several reasons you might want to do this, efficiency and maintainability being probably the most important.
- Ralph Johnson

In software world, it is very difficult to design and development a right system at first time. Thus keeping this is in mind, refactoring analysis was carried out to improve the SuD for better performance and maintainability.

2. When to refactor?

Refactoring is a systematic way to clean-up buggy but working code. It is needed when a system lives with bad designs, wrong decisions and poor code. Following are some of the situations which call for refactoring:
It was very difficult to get the system correct the very first time
Lack of understanding of the problem domain
Heavy presence of monolithic code; lack of modularization
Programs that are hard to understand, hard to maintain, contain heavy duplication of logic/code etc. Following are the top ten reasons of bad code smells that ask for refactoring:
Duplicated code
Long method
Large class (too many responsibilities)
Long parameter list (missing object)
Too many case statements
Same class changes differently depending on the additions
Dependency of method is too high from other objects
Lazy class (does not do too much)
Class with too many delegating methods
Too much coupled amongst the classes, accessor classes
Overall slow response time to client requests

3. Refactoring Benefits

Some of the main benefits of refactoring are elaborated below:
Code manipulation in safe environment
Improves scalability, maintainability and portability of the existing system, where possible
Leads to better understanding of existing code
Identifies and reduces an existing system’s performance bottlenecks

No comments:

One new learning / day - however small it is

Read a blog / or article Watch TED talk  Read a small self-help book (many free eBooks available with less than 100 pages/can be completed i...