Drools rule engine - if the Fact object argument is null how to deal with

Problem Scenario

In technical exchange group (QQ: 715840230) have students ask the question:

To kiesession inside pass fact, if we did not check the fact there is some input fields may be null value. But if you do input validation on the outside, a change in the rules, the required fields fact not the same, enter the check have to follow the change, coupled relatively strong. Is there any better way to do that?

Asked Questions

In view of this fact, has little problem with a rules engine, the more important thing is to see the business logic.

For example, for a corporate credit rating, it involves three dimensions: firm age, registered capital and corporate age. Of course, in this example, the higher the value the higher the evaluation value obtained is tentatively.

On this example to answer the above questions. From the terms of two dimensions:

Reduce coupling

To reduce the coupling true, then the three dimensions may be split, the object is not in fact a pass, but three rules, each rule corresponding to the calculated value, the final addition result by one. With this scheme, we issue fact is null does not exist.

Increase judgment

If the judge rules in a business three of them, then the fact the object is null, it would require special handling up. For example, in only when we get the type of fact for the enterprise objects without specific qualification. So long as the object enters the enterprise, it will be a matching rule, and then the specific portion on the score calculation processing.

Another case is then defined by the condition customize some processing functions, such object is obtained by the fact a custom function processed into the desired results, then do then summarized in the.

Other methods

So, the problem for students who, he wanted to be verified by the investigation objects before inserting fact, this is actually a choice, select the default value of the property is null score is zero. For his doubts this, it answers given in exchange for the group:

This value does not pass or ignore this value, is actually a process of this value. Similarly, this process may be in a rule, and process more flexible. For example, the scoring, if an item does not pass, this one is likely that the default 0, but if you pass a null value, you may be treated to null in the rules, set to 0, you can even be the null value process, is provided to a negative value.

Related video technology

CSDN Institute: "Drools7 Rules Engine Advanced Course"

CSDN Institute: "Drools7 Rule Engine Guide"

CSDN Institute: "Drools7 Series Package"

Original link: http://www.choupangxia.com/2019/07/26/drools%e8%a7%84%e5%88%99%e5%bc%95%e6%93%8e-%e5%a6% 82% e6% 9e% 9cfact% e5% af% b9% e8% b1% a1% e5% 8f% 82% e6% 95% b0% e4% b8% banull% e5% a6% 82% e4% bd% 95% e5% a4% 84% e7% 90% 86 /

Guess you like

Origin www.cnblogs.com/secbro/p/11260704.html