class InvoiceService {
shippingCost(order: Order) {
const w = order.items.reduce((s, i) => s + i.weightKg * i.qty, 0);
const base = order.address.country === "DE" ? 5 : 15;
return order.isExpress ? base * 2 + w : base + w;
}
}
Feature envy
This is "Feature envy": a method that cares more about another object's data than its own. This method only uses the fields of order. So it probably belongs on Order, or on a shipping policy object.
"Shotgun surgery" is wrong. It means one change needs edits across many classes, and this snippet does not show that.
Read more