title: A simple design pattern to develop a small Rule-Engine
body: <p>I have a requirement which take lots of rules validated against the java value objects and produces results. (we cant use any rule engine apps in our company, lots of formalities and lots of questions to be answered).
  So, rather than implementing the rules as ifs' in java code I suggested to implement a small rule engine, Simple and Extensible. 
  Which design pattern to follow?</p>
  
  <p>I have added below a rough xml structure of the rules defined.</p>
  
  <pre><code>  &lt;rule-set&gt;    
      &lt;name&gt;Example1&lt;/name&gt;
      &lt;description&gt;Example rules defined&lt;/description&gt;
  
      &lt;beans&gt;
          &lt;bean class="com.example.Customer" alias="cust"/&gt;
          &lt;bean class="com.example.Account" alias="acnt"/&gt;
          &lt;bean class="com.example.Transaction" alias="trans"/&gt;
      &lt;/beans&gt;
  
      &lt;rule name="CustomerInfo" description="This rule validates if all the customer values are present"&gt;
          &lt;if lhs="cust.getFirstName" rhs="null" operator="!="/&gt;
          &lt;if lhs="cust.getLastName" rhs="null" operator="!=" logicaloperator="&amp;amp;&amp;amp;"/&gt;
          &lt;if lhs="cust.getCountry" rhs="null" operator="!=" logicaloperator="||"/&gt;
          &lt;if lhs="cust.getCity" rhs="null" operator="!=" logicaloperator="&amp;amp;&amp;amp;"/&gt;
          &lt;if lhs="cust.getPhone" rhs="null" operator="!=" logicaloperator="&amp;amp;&amp;amp;"/&gt;
          &lt;if lhs="cust.getEmail" rhs="null" operator="!=" logicaloperator="&amp;amp;&amp;amp;"/&gt;
          &lt;then do="cust.completeFlag" arg1="true"/&gt;
      &lt;/rule&gt;
  
      &lt;rule name="Transaction" description="Transfer the money from one ac to another"&gt;
          &lt;if lhs="trans.fromAccount" operator="!=" rhs="null"/&gt;
          &lt;if lhs="trans.toAccount" operator="!=" rhs="null"/&gt;
          &lt;if lhs="trans.fromAccount.balance" operator="&gt;" rhs="trans.getTransaferAmount"/&gt;
          &lt;then do="trans.fromAccount.debit" arg1="trans.getTransaferAmount"/&gt;
          &lt;then do="trans.toAccount.credit" arg1="trans.getTransaferAmount"/&gt;
      &lt;/rule&gt;
  
  &lt;/rule-set&gt;
  </code></pre>
  
  <p></p>