A First Look at Logic

This sample problem (Customers, Orders and Parts - shipped in the download) is a simple way to illustrate the use and operation of business logic.  The requirement Customer's balance may not exceed their credit limit is addressed as follows:

  • Constraint Logic

Far beyond simple single-attribute validations, the requirement is multi-attribute constraints, such as this Customer Constraint:

balance < creditLimit

  • Derivation Logic
Constraints are the most familiar form of business logic, but derivations and actions are the most valuable, per dependency / re-use automation noted below.  Derivations here include multi-table derivation rules such as

Customer.balance = sum(order.total where paid = false)

Note that:
  1. Derivations are multi-table, as in the example above

  2. Derivations can chain, both to constraints, and other derivations:

         Order.total = sum(Lineitem.amount)
         Lineitem.amount = quantity * partPrice
         Lineitem.partPrice = copy(Part.price)


  3. Chaining, ordering and dependencies are automatically handled (logic is declarative, somewhat similar to a spreadsheet)

  4. Derivations can include if/else logic, state transition logic, and reference related data

  5. Derivations are highly optimized to eliminate / optimize SQLs.  For example, changing an orders's date does not retrieve the customer, and paying an order adjusts the customer with a 1-row update -- not a aggregate query

  • Action Logic - address requirements such as auditing, copying (e.g., an order clone), or invoking a business rules engine

Logic is declarative: what not how

Logic is an alternative to the procedural code you typically write to enforce your business logic.  Procedural if often described as telling the computer how to do something, while declarative means you just say what the end result should be.  This has some very practical advantages, as described below.

Automatic Re-use


Automatic Ordering


Automatic Optimizations


Comments