How to Effectively Refactor Legacy Code ?
In the life of a software engineer, substantial amount of time is spent on working with legacy code. A legacy code may require attention either to add a new feature, fix a bug or optimize the application. Michael Feathers in his book Working Effectively with Legacy Code outlines five important steps to improve the efficiency of refactoring legacy code,
- Identify the change point
- Find the inflection point
- Break dependencies
- Write tests
- Refactor
Assume there exists a car rental system, where any customer can rent a car. For each rental a car will be assigned from the available inventory and a price quote engine would calculate price.
Now the head of sales comes up with a new requirement to offer prices based on customer start date. So, this legacy car rental application has to be updated to accommodate his request.
Identify the change point
A point at which the change has to be made needs to be identified first. Based on the architecture above, to support the new pricing feature the change has to be made to…