jeudi 26 février 2015

Adding a parameter to a method that's used called from 100 different places in my project - What's the proper approach?

So I'm working on a codebase, and there's a utility class that deals with generating excel documents for users.


It has a method called putDataInRowColumn(row, column, data)


It has quite a few methods like putObjectsIntoExcel(myBigClass blah) and putObjectsIntoSpecialExcelType(myBigClass blah)


which calls a load of methods like putObjectIntoSpecialRowType(blah.foo(), rowIndex, specialConditions) and putObjectIntoTotallydifferentRowType(blah.bar(), rowIndex, specialConditions)


The point of all this is that the method putDataInRowColumn(row, column, data) gets called a metric buttload, from a bunch of different places. like 100+.


Now, given this legacy code, I needed to modify the method to take additional parameters - styling information. 99% of the methods will now take 'null' as a fourth argument, and 1% will receive an object which contains styling information.


I modified the method signature, to receive the additional parameter, but I found myself having to write a regex to find/replace all of the method calls. it worked, but this felt like the wrong way to go about this.


How should I have done it?


Aucun commentaire:

Enregistrer un commentaire