java 业务规则验证的框架/设计模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10870154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 02:54:35  来源:igfitidea点击:

Framework / Design pattern for business rule validation

javadesign-patternsframeworks

提问by ilovetolearn

What kind of framework / design pattern should I use for application which possibly has 1000 over biz rule validations?

对于可能有 1000 多个商业规则验证的应用程序,我应该使用什么样的框架/设计模式?

The type of systems I am working on consist of lots of input forms which allow users to enter. Each input form has different sections.

我正在研究的系统类型由许多允许用户输入的输入表单组成。每个输入表单都有不同的部分。

i.e. Form A has Section A/B/C/D. Form B has section B/C/D

即表格 A 有 A/B/C/D 部分。表格 B 有 B/C/D 部分

Some of these biz rule validation are common to both forms, I am looking at a approach to reuse the rules as well.

其中一些商业规则验证对两种形式都是通用的,我也在寻找一种重用规则的方法。

How do I build a robust business rule validation framework?

如何构建健壮的业务规则验证框架?

回答by Tomasz Nurkiewicz

  • droolsframework is specifically designed to evaluate business rules

  • springframework allows writing beans using dynamic languages like groovyand jruby. You can easily plug JavaScript

  • strategy design patternseems like a good fit: implement each rule as a separate strategy and run them one after another.

  • similar chain of responsibilitypattern can be used: each rule either fails or succeeds and passes control to next rule

  • drools框架专门用于评估业务规则

  • spring框架允许使用groovyjruby等动态语言编写 bean 。您可以轻松插入JavaScript

  • 策略设计模式似乎很合适:将每个规则作为一个单独的策略来实现,然后一个接一个地运行它们。

  • 可以使用类似的责任链模式:每个规则要么失败要么成功,并将控制权传递给下一个规则

回答by Jord?o

A good pattern to implement business rules is the Specification pattern. It's a combination of Strategy, Compositeand Interpreterthat can make for parameterized and easily combinable rules. Be sure to also look at the original paper (pdf)by Fowler and Evans, and take a look at the book Domain Driven Designif you can.

实现业务规则的一个很好的模式是规范模式。它是StrategyCompositeInterpreter的组合,可以制定参数化和易于组合的规则。一定还要看看Fowler 和 Evans的原始论文 (pdf),如果可以的话,看看《领域驱动设计》这本书。