How do you decide whether to rewrite, refactor, or extend existing code?

Behavioral