Object rules perform all information processing
All essential processing logic in the system should be specified as individual rules attached to applicable objects, not processes. There are two important reasons for this principle.
Reason 1
There may be many scenarios causing a change to an object. If the processing logic is spread across various scenarios, any change to the logic needs to be propagated throughout the scenarios. With the object rules approach, for each object you specify all rules that make sense from that particular object point of view. None of these rules are duplicated anywhere else in the system.
For example, Aware IM will automatically evaluate the following validation rule on account whether a new holder is linked to the account, or the existing holder’s age is changed:
IF Account.Holder.Age < 16 THEN REPORT ERROR 'Account holder must be 16 years old or over'
Reason 2
Object rules are independent from each other and therefore allow configuring each step in multi-step procedures separately from other steps. A really complex procedure would be difficult to configure as a single process because of multiple conditional, parallel or overlapping steps it may contain.
Let us consider an example of a withdrawal transaction, which requires an approval by an authorised person if the withdrawal amount exceeds 5000. Before the transaction is approved all necessary validation checks should be made. After the approval the account balance should be updated accordingly.
We will first demonstrate how this procedure can be implemented by object rules. We configure WithdrawalTransaction object with its State attribute initialised to New. We then attach a pre-approval validation rule to the object:
IF WithdrawalTransaction.State = 'New' AND WithdrawalTransaction.Account.Balance < ABS(WithdrawalTransaction.Amount) THEN REPORT ERROR 'Insufficient funds on account'
In a similar manner we could attach all other validation rules as necessary. Next, we need to see if the transaction can be approved automatically, which is done by attaching the following rule to WithdrawalTransaction:
IF WithdrawalTransaction.State = 'New' AND ABS(WithdrawalTransaction.Amount) < 5000 THEN WithdrawalTransaction.State = 'Approved'
If the transaction amount is larger the transaction will wait for manual approval (or rejection) by an authorized person. The manual approval will change its state to ‘Approved’ signalling the start of the second step in the processing of the transaction, namely the updating of the account balance. This can be done by attaching the following rule to Account object (note that Transaction here is a name of object group that has WithdrawalTransaction as well as objects for other transaction types as its members):
Account.Balance = SUM Transaction.Amount WHERE (Transaction IN Account.Transactions AND Transaction.State = 'Approved')
Let us now see how the same procedure could be configured using processes, a more traditional approach, which is not recommended for use in Aware IM. We would need two processes. The first is called EnterTransaction and contains the following sequential rules:
ENTER NEW WithdrawalTransaction WITH WithdrawalTransaction.Account = Account
IF ABS(WithdrawalTransaction.Amount) < 5000 THEN WithdrawalTransaction.State = 'Approved' REDUCE Account.Balance BY ABS(WithdrawalTransaction.Amount)
The second process is called 'ApproveTransaction' and used by an authorised person to complete pending transactions. It contains the following rules:
WithdrawalTransaction.State = 'Approved'
REDUCE Account.Balance BY ABS(WithdrawalTransaction.Amount)
What is wrong with these processes? Several things:
- The rule updating the account balance is duplicated in both processes. All other similar processes, configured to handle other transaction types, would also have to include a step updating the account balance. Compare this with the object rules approach where there is only one rule on the Account object that updates the balance whenever a new transaction is applied.
- Transaction processing logic is entangled with the user interface step that allows the user to enter the transaction details. If the transaction needed to be created without the user input, for example as a part of a funds transfer transaction, the validation and calculation rules would have to be duplicated in the transfer process.
- If the logic of updating account balance needs to be changed, the change would need to be propagated throughout all the processes configured in the system that update account balance.