私は、Javaの値オブジェクトに対して検証された多くのルールをとり、結果を生成するという要件があります。 (当社ではルールエンジンのアプリケーションを使用することはできません。多くの手続きや質問に答える必要があります)。 したがって、Javaコードでifs 'のようなルールを実装するのではなく、シンプルで拡張可能な小さなルールエンジンを実装することを提案しました。 どのデザインパターンに従うのですか?小さなルールエンジンを開発するためのシンプルなデザインパターン
以下に、定義されたルールの概略xml構造を追加しました。
<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>
。 –
@DonRoby - 修正済み、ありがとうございます。 –