Software Architecture - (Event Driven) Rule
Table of Contents
1 - What is a Rule?
A rule consists of a conditional expression that is specified using the attributes defined in a corresponding event structure and a rule action that takes place when the rule condition is satisfied by an instance of the event structure.
Event management policies define how an event instance is handled once the rule action is executed. This, in a nutshell, describes how a typical rules-based system works.
Typically, rules follow Event-Condition-Action (ECA) rule semantics where an event happens and if a rule condition evaluates to true for this event, then some prescribed action is performed. The ECA components are defined as:
- Event – the state information for the process
- Condition – the Boolean condition that evaluates to true or false for the event
- Action – the action to be carried out if the rule condition evaluates to true for the event
2 - Articles Related
3 - Standard Notation
The standard notation for ECA rules is:
ON <event structure> IF <condition> THEN <action>
- the ON clause identifies the event structure for which the rule is defined,
- the IF clause specifies the rule condition,
- and the THEN clause specifies the rule action.
4 - Example
An example of a rule is the following: If a customer chose to fly Abcair Airlines to Orlando and if his stay in Orlando is more than 7 days, then offer an Acar rental car promotion to him. Using the ECA notation, this rule is:
ON AddFlight (Custid, Airline, FromCity, ToCity, Depart, Return) IF Airline = 'Abcair' and ToCity = 'Orlando' and Return-Depart >= 7 THEN OfferPromotion (CustId, 'RenralCar', 'Acar')
- The ON structure identifies the event structure for this rule.
- The IF clause defines the rule condition using variables in the event structure.
- The THEN clause defines the commands that represent the action for this rule.