31
Replace Parameter with Query
Goal
When a function can compute its own answer from already-available state, callers don't have to pre-compute it.
Before the refactoring
const basePrice = order.qty * order.itemPrice;
const level = discountLevel(order);
const final = discounted(order, basePrice, level);After the refactoringconst final = discounted(order); // computes basePrice and level itselfSavings
Signatures shrink; consumers stop doing the function's homework.
Note
If the query has side effects or is expensive, passing the value is genuinely better — only replace when the query is pure and cheap.