Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you refactor a class that is constantly being edited?

Over the course of time, my team has created a central class that handles an agglomeration of responsibilities and runs to over 8,000 lines, all of it hand-written, not auto-generated.

The mandate has come down. We need to refactor the monster class. The biggest part of the plan is to define categories of functionality into their own classes with a has-a relationship with the monster class.

That means that a lot of references that currently read like this:

var monster = new orMonster();
var timeToOpen = monster.OpeningTime.Subtract(DateTime.Now);

will soon read like this:

var monster = new Monster();
var timeToOpen = monster.TimeKeeper.OpeningTime.Subtract(DateTime.Now);

The question is: How on Earth do we coordinate such a change? References to "orMonster" litter every single business class. Some methods are called in literally thousands of places in the code. It's guaranteed that, any time we make such a chance, someone else (probably multiple someone elses) on the team will have code checked out that calls the .OpeningTime property

How do you coordinate such a large scale change without productivity grinding to a halt?

like image 597
Yes - that Jake. Avatar asked Feb 24 '09 21:02

Yes - that Jake.


2 Answers

You should make the old method call the new method. Then over time change the references to the old method to call the new method instead. Once all the client references are changed, you can delete the old method.

For more information, see Move Method in Martin Fowler's classic, Refactoring.

like image 153
Patrick McElhaney Avatar answered Nov 16 '22 02:11

Patrick McElhaney


One thing you can do is to temporarily leave proxy methods in the monster class that will delegate to the new method. After a week or so, once you are sure all code is using the new method, then you can safely remove the proxy.

like image 44
Eddie Avatar answered Nov 16 '22 04:11

Eddie