Interface Design for Testability
Good interfaces make testing natural:
Accept dependencies, don't create them
// Testable function process_order(order, payment_gateway): ... // Hard to test function process_order(order): gateway = new PaymentGateway() ...Return results, don't produce side effects
// Testable function calculate_discount(cart) -> Discount: ... // Hard to test function apply_discount(cart): cart.total -= discountSmall surface area
- Fewer methods = fewer tests needed
- Fewer params = simpler test setup