Object rules are attached to the right objects

A rule attached to an object should specify the logic that applies to that object, not other objects. In particular, a rule that modifies an attribute of an object should be attached to the object to which the attribute belongs. There are two important reasons for this principle.

The right rule attached to the wrong object will lead to the wrong results.

When you need to make a change to an object configuration you will see all relevant rules in one place. You will not need to search through the system to see what other object rules can make a change to the object and when. This may also help reducing the number of similar rules, which will further simplify the system.

Let us illustrate this principle with examples. Consider a validation rule that a person must be 16 or over to be an account holder. This rule should be attached to the Account object and can be specified as follows:

IF Account.Holder.Age < 16 THEN 
   REPORT ERROR 'Account holder must be 16 years old or over' 

However, the same rule attached to the Person object would have a very different meaning:

IF Person.Age < 16 THEN 
   REPORT ERROR 'Account holder must be 16 years old or over' 

This is because the latter rule would essentially state that no person under 16 can be registered in the system, whether to be an account holder or for any other purpose. While this may very well be another business rule on its own right, it is definitely not what the original rule was meant to specify.

As for the object-modifying rules, consider an example when an account balance is updated following a financial transaction applied to the account. A rule on the transaction could update the account balance:

IF Transaction.State WAS CHANGED TO 'Approved' THEN 
   INCREASE Transaction.Account.Balance BY Transaction.Amount 

Now suppose that there are a number of transactions in the system, each represented by a separate object. The above rule would have to be configured, essentially duplicated, for each specific transaction object. The correct way of updating the account balance, and also a safer one, would be for the account to update its own balance following the addition of a new transaction. This is done by attaching the following rule to Account object:

Account.Balance = SUM Transaction.Amount WHERE (Transaction IN Account.Transactions AND Transaction.State = 'Approved') 

Note that Aware IM will execute the above rule whenever any of the account details change, including the transaction list, or the state of a transaction, that is already in the list, changes. We can be more specific and state that the balance should be updated only when the transaction list changes (i.e. a new transaction is added), but not when other account details change. Then we would need to add a corresponding condition to the above rule:

IF Account.Transactions WAS CHANGED THEN 
   Account.Balance = SUM FinancialTransaction.Amount WHERE 
   (FinancialTransaction IN Account.Transactions AND FinancialTransaction.State = 'Approved') 

In this case, however, we should also remember to update the balance when a pending transaction is approved, which can be done by adding the following rule to Account:

IF Transaction FROM Account.Transactions WAS CHANGED AND ChangedTransaction.State WAS CHANGED TO 'Approved' THEN 
   Account.Balance = SUM FinancialTransaction.Amount WHERE
    (FinancialTransaction IN Account.Transactions AND FinancialTransaction.State = 'Approved')