विकसित करने के लिए एक साधारण डिज़ाइन पैटर्न मेरे पास एक आवश्यकता है जो जावा वैल्यू ऑब्जेक्ट्स के विरुद्ध बहुत से नियमों को मान्य करता है और परिणाम उत्पन्न करता है। (हम अपनी कंपनी में किसी भी नियम इंजन ऐप का उपयोग नहीं कर सकते हैं, औपचारिकताओं और कई सवालों का जवाब देने के लिए)। तो, जावा कोड में नियमों को लागू करने के बजाय, मैंने एक छोटे नियम इंजन, सरल और एक्सटेंसिबल को लागू करने का सुझाव दिया। किस डिजाइन पैटर्न का पालन करने के लिए?एक छोटे नियम-इंजन
मैंने परिभाषित नियमों की एक मोटाई 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>
इस यूआरएल नहीं रह गया है आप उस लेख के लिए ले जाता है। –
@ डोनरोबी - सही, धन्यवाद। –