Example of a Pivot Point
So here's an example:
setMeasurement("Gas Equivalent", 10, x, y ,z);
setMeasurement("Production', 5, a,b,c);
We have lots of these in hundreds of tests. We had an AHA moment, where GasEquivalent was no longer on equal footing with production, it is subservient.
What we really want is something like: (Keep the goal in mind!)
setGasEquivalent("Production", 10)
setMeasurement("Production", 5,a,b,c)
If you were to make a change in the business logic and then in your tests. It would take several days before you could check in. On the otherhand, if you have a pivot point, you can keep checking in and do the work in less time.
The pivot point in this refactoring is creating a method:
setMeasurementX(name, value, x, y, z) {
setMeasurement(name, value, x, y, z)
}
So, we now change all the tests - with a single character.
setMeasurementX("Gas Equivalent", 10, x, y ,z);
setMeasurement("Production", 5, a,b,c);
You haven't changed the contract (sometimes you need to add a parameter or something, do as LITTLE AS POSSIBLE)
You can check in lots as you make the change - remember all your test will continue to pass.
Make the change in the business logic (remember to find a pivot point in the business logic if it is a bug change down there too...).
All your tests should fail.
Now make this change in setMeasurementX
setMeasurementX(name, value, x, y, z) {
setGasEquivalent("Production", value)
}
All your tests will pass
Inline setMeasurementX.
setMeasurementX was your pivot point - reducing a large problem to a small change.
0 Comments:
Post a Comment
<< Home