Bir java değer nesnesine karşı doğrulanmış çok sayıda kural alan ve sonuç üreten bir gereksinim var. (şirketimizde herhangi bir kural motoru uygulamasını kullanamayız, birçok formalite ve cevaplanacak birçok soruya cevap veremiyoruz). Yani, kuralları java kodunda ifs 'olarak uygulamak yerine, basit ve genişletilebilir küçük bir kural motoru uygulamanızı önerdim. Hangi tasarım desen takip edilir?Küçük bir Kural Motoru geliştirmek için basit bir tasarım deseni
I belirlenen kurallar kaba bir XML yapısı aşağıda ekledik.
<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>
Bu URL'ye, artık bu yazıya götürür. –
@DonRoby - düzeltildi, teşekkürler. –