Business Context

Story: Place Order.  

Task/Requirement: Check Credit.  (or, your methodology / terminology).

 

Business view

When placing an order, check credit - elaborated as follows (the "cocktail napkin spec")... 

A good spec - clear, concise.

 


Conventional Design

In a conventional approach, you might design the following pseudocode:

  1. Compute the LineItem.amount
    1. Read the Product to get the Price
    2. Multiply by qty_ordered to compute the amount
  2. Update the PurchaseOrder.amount_total
    1. Read the PurchaseOrder
    2. Increase the amount_total
    3. Update the PurchaseOrder (to cache)
  3. Update the Customer.balance
    1. Read the Customer,
    2. Increase the balance
    3. Update the Customer (to cache)
  4. Check that balance <= credit_limit
    1. Throw exception with error message for UI handling
    2. Rollback the transaction

But Place Order is just one Story.  We need analogous logic for all the related Stories (Detete Order, Pay Order, etc etc).

 


Reactive Rule Approach

And that's the power of declarative reactive logic.  You simply state the rules below (nearly the same as the cocktail napkin).

 

Reactive Rule Execution: Watch, React and Chain

And (as in a spreadsheet), the rules are automatically applied to all incoming transactions:

  1. They watch for changes in data referenced by rules
  2. They react to changes in referenced data.  Execution order is dictated by dependencies.  
  3. They chain - including across tables.  So changes to line items affect their order, which affect their customer

Note it works across tables.  Consider the customer balance - the sum of the unpaid order amounts.
It works rather like a spreadsheet.  Order changes are watched, and the balance is

Observe persistence is automated (no need to read/write the customer, or deal with transactions).  And it's optimized:

 


Bottom Line

That means the following Stories are automatically addressed with our 5 "cocktail napkin" rules:

A conventional approach would require hundreds of lines of code, might easily miss corner cases, and be tedious to maintain.