You didn't fall prey to PrematureGeneralization; you didn't try to write reusable code ahead of time. When you're about to perform CopyAndPasteProgramming, then you cut it, paste it into a reusable module (class, function, method, whatever), and call it from both the old code (replacing the code you just cut) and the new (where you were about to paste it).
(Consider this a placeholder for a real pattern. Please feel free to replace it. Comments, suggestions, additions greatly appreciated. --PaulChisholm)
Inspired by PrematureGeneralization. See also CodeHarvesting.
In ExtremeProgramming we call this SwitchingHats. You have to add some functionality:
Refactor, refactor, refactor. Refactor some more. Then refactor it a bit. Why not let the CopyAndPasteProgramming code "age" a little before doing all this? I like the arguments presented in CodeHarvesting; they seem to fit my experiences pretty well.