45
Move Statements to Callers
Goal
Statements that vary by caller move out of the function so each caller chooses its own setup or follow-up.
Before the refactoring
function emit(line) {
log.write(line);
metrics.tick();
}After the refactoringfunction emit(line) { log.write(line); }
emit('startup');
metrics.tick();Savings
The function's body becomes about its single responsibility; callers express their differences directly.
Note
If most callers want the moved statements, you've created duplication — the inverse of Move Statements into Function is only an improvement when callers genuinely differ.