本文介绍了什么模式/模式最适合发展规律/决策引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个决策引擎/规则评估引擎。例如:

I am working on a decision engine / rule evaluation engine. For example:

输入:客户和所有客户做的犯罪

Input: Customer and all the offences done by the customer

输出:罪行后果

一个样本情况是:

输入:客户(的Jhonny Chimpo,999-00-1111),犯罪(布罗克窗口,老板打耳光,脚踢团队主管在他的腹股沟)

Input: Customer(Jhonny Chimpo, 999-00-1111), Offences ( Broke window, slapped boss, kicked team lead in his groin)

输出:获取解雇

所以我想写的一块code评估基于每个进攻和进攻相结合的规则不同的罪行。目前的code是if和else语句的只是一个迷宫。我相信这样的业务问题很常见。通常用什么样的设计/企业模式来解决这样的问题呢?

So the piece of code I want to write evaluates different offences based on rules for each offence and combined offence. The current code is just a maze of if and else statements. I am sure such business problems are common. What design/enterprise pattern is usually used to solve a problem like this?

这是不是规范的模式?我想code到对扩展开放,干净而有弹性。

Is it the specification pattern? I want the code to be open for extension, clean and flexible.

推荐答案

基本上业务规则看起来像

Basically business rules look like

forall rules:
  if <condition> then doAction();

怎么样使用严重程度评分,也许是多余的频繁恶人奖金分类的所有罪行,有些罪行可能成为时间限制和任何必需的。

What about categorizing all offences by severity using scores, perhaps extra bonus for frequent "evil-doers", some offences may become time-barred and whatever required.

然后,一个算法的草图可以是:

Then a rough draft of an algorithm could be:

  • 在一个客户的所有得分之和(加权)
  • 比较最大

这是简单的用数据结构,而不是很多(可能是深度嵌套)if..then..else的事情。

This would be straight forward using data structures instead of many (possibly deeply nested) if..then..else things.

这篇关于什么模式/模式最适合发展规律/决策引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 01:03