A business rule specifies behavior or constraints in the problem domain. It is expressed in domain terms such as product, price, discount, or shipping—not in technical terms such as databases, AJAX requests, or retries. section 18.22
Use these distinctions when organizing business code:
- Separate business rules from DOM updates and global state so the rules can be tested without loading pages, clicking buttons, or scraping rendered values. section 4.4
- Keep business rules distinct from generic cart operations. A cart is common across stores; a free-shipping threshold can be specific to one business. section 5.11
- Classify calculations by their knowledge: cart structure, item structure, business rules, or array utilities. These groupings can become separate layers. section 5.6
- Do not mistake important infrastructure logic for a domain rule. Database fallback and web-request retries handle a changing technical environment and belong in the interaction layer. section 18.22
Free shipping and tax
A calculation such as gets_free_shipping(cart), which returns whether the cart total reaches 20, expresses a business rule. calc_tax(amount), which applies a 10% rate, is another. update_shipping_icons belongs to the surrounding action code; it prepares carts and updates buttons rather than defining the rule itself. section 5.6 section 5.11
C I function add_item(cart, name, price) { var new_cart = cart.slice(); #1 new_cart.push({ name: name, price: price }); return new_cart; }
C I B function calc_total(cart) { #2 var total = 0; for(var i = 0; i < cart.length; i++) { var item = cart[i]; total += item.price; } return total; }
B function gets_free_shipping(cart) { return calc_total(cart) >= 20; }
B function calc_tax(amount) { return amount * 0.10; }
Inspect the annotated calculations to see how cart operations, item operations, business rules, and array knowledge differ. section 5.6




