Tengo un requisito que toma muchas reglas validadas contra los objetos de valor de Java y produce resultados. (No podemos usar ninguna aplicación de motor de reglas en nuestra empresa, muchos trámites y muchas preguntas para responder). Entonces, en lugar de implementar las reglas como si fuesen 'en código Java, sugerí implementar un motor de reglas pequeño, simple y extensible. ¿Qué patrón de diseño seguir?Un patrón de diseño simple para desarrollar un pequeño Rule-Engine
He añadido debajo una estructura xml aproximada de las reglas definidas.
<rule-set>
<name>Example1</name>
<description>Example rules defined</description>
<beans>
<bean class="com.example.Customer" alias="cust"/>
<bean class="com.example.Account" alias="acnt"/>
<bean class="com.example.Transaction" alias="trans"/>
</beans>
<rule name="CustomerInfo" description="This rule validates if all the customer values are present">
<if lhs="cust.getFirstName" rhs="null" operator="!="/>
<if lhs="cust.getLastName" rhs="null" operator="!=" logicaloperator="&&"/>
<if lhs="cust.getCountry" rhs="null" operator="!=" logicaloperator="||"/>
<if lhs="cust.getCity" rhs="null" operator="!=" logicaloperator="&&"/>
<if lhs="cust.getPhone" rhs="null" operator="!=" logicaloperator="&&"/>
<if lhs="cust.getEmail" rhs="null" operator="!=" logicaloperator="&&"/>
<then do="cust.completeFlag" arg1="true"/>
</rule>
<rule name="Transaction" description="Transfer the money from one ac to another">
<if lhs="trans.fromAccount" operator="!=" rhs="null"/>
<if lhs="trans.toAccount" operator="!=" rhs="null"/>
<if lhs="trans.fromAccount.balance" operator=">" rhs="trans.getTransaferAmount"/>
<then do="trans.fromAccount.debit" arg1="trans.getTransaferAmount"/>
<then do="trans.toAccount.credit" arg1="trans.getTransaferAmount"/>
</rule>
</rule-set>
Esta dirección de Internet ya no le lleva a ese artículo. –
@DonRoby - corregido, gracias. –