liveBook · Manning

Validation rule

As explained in Grokking Simplicity

A rule that specifies behavior or constraints within the problem domain modeled by software.

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

How Grokking Simplicity covers it

How deep it goes
Defines domain-language boundaries and demonstrates extraction into calculations, while deferring fuller layer design to later treatment.
Examples
Uses free shipping, tax calculation, shopping carts, DOM updates, database fallback, and web-request retries as contrasting examples.
What you can do after
Diagnose/debug with it by locating domain calculations, separating them from actions, and identifying misplaced infrastructure logic.
How it connects
Connects business rules with domain rules, cart operations, stratified design, interaction layers, testing, reuse, and maintenance.

Also explained in

Compare how 5 books explain validation rule →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Simplicity. The section links point to the parts of the book it draws on.