业务规则应该在哪里实施?

发布于 2024-10-07 14:40:22 字数 1431 浏览 0 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

回首观望 2024-10-14 14:40:22

首先,您必须对“业务规则”有一个明确的定义。有很多候选者:

  1. 有关您产品的信息。
  2. 有关销售的规则,取决于时间、地点、客户、产品、月相(也称为月份的截止日期)、季节等。
  3. 用户角色(例如,普通客户与优先客户等)
  4. 有关应付账款和应收账款的规则
  5. GAAP 规则

到底是什么意思?这是一个模糊的问题,如果你允许的话,它可能会变得相当大。

对于它们在代码中的位置,您有很多选择:

  1. 数据驱动,存储在数据库中
  2. Rete 规则引擎中的表达式。
  3. 如果您正在编写面向对象的内容,请选择中级课程。
  4. 属性或配置文件(如果您正在进行声明性编程)。
  5. 用 JavaScript 之类的东西表达的可执行规则。
  6. 在您的 ERP、MRP、应付账款和应收账款系统中。
  7. 以您的应用程序组合在一起的 Web 服务为前端。

你看到你所提出的问题了吗?您的问题意味着您有一个明确定义的问题,并期望得到一个简单、简洁的答案。事实上,这是一个广泛的话题。

First you'll have to have a clear definition of what a "business rule" is. There are a bevy of candidates:

  1. Information about your products.
  2. Rules regarding sales that depend on time, location, customer, product, phase of the moon (aka closing date of the month), season, etc.
  3. User roles (e.g., normal versus preferred customers, etc.)
  4. Rules around accounts payable and receivable
  5. GAAP rules

What exactly do you mean? It's a vague question that can be quite large if you let it.

You have lots of choices as to where they go in your code:

  1. Data driven, stored in databases
  2. Expressions in a Rete rules engine.
  3. Middle tier classes if you're writing OO.
  4. Properties or configuration files if you're doing declarative programming.
  5. Executable rules expressed in something like JavaScript.
  6. In your ERP, MRP, A/P and A/R systems.
  7. Fronted by web services that your apps compose together.

Do you see the problem you're opening up? Your question implies that you have a well-defined problem and expect a simple, neat answer. The truth is that it's a broad topic.

三人与歌 2024-10-14 14:40:22

这是一个非常普遍的问题,很难回答——但我建议看一下行为驱动开发< /a> 作为将业务规则置于开发核心的一种方式。

This is quite a generic question and hard to answer -- but I'd say take a look at Behaviour Driven Development as a way of keeping business rules at the heart of your development.

巷子口的你 2024-10-14 14:40:22

我建议您研究 MVC 范例 - 模型视图控制器。视图中不应该有业务逻辑,它应该全部在模型中。

I suggest you investigate the MVC paradigm - Model View Controller. There should be no business logic in the view, it should all be in the model.

太傻旳人生 2024-10-14 14:40:22

答案取决于多种因素,例如

  • 客户是否应该更改规则?
  • 规则多久改变一次?
  • 是否应该在不重新启动应用程序的情况下部署更新的规则?

如果上述所有问题的答案都是“是”,那么您正在寻找一个规则引擎(drools、ilog 等)来实现您的规则。

如果您的答案是“否”,那么另一种方法是在代码中对规则进行建模,并牢记下面的

  • 封装1 个业务规则在自己的类中,以便可以独立测试、定制和更新,
  • 以业务提及的方式命名规则(通用语言)
  • 了解规范模式 (域驱动设计)。我认为这种表达规则的方式非常直观和明确

。从此处复制

EligibleForDiscountSpecification isEligibleForDiscountRule = new EligibleForDiscountSpecification();
isEligibleForDiscountRule .IsSatisfiedBy(customer)

The answer depends on multiple factors like

  • should customer make changes to the rules?
  • How often the rules change?
  • Should updated rules be deployed without restarting the application?

If answer is YES to all of them above then a rules engine (drools, ilog etc) is what you are looking for to implement your rules

If your answer is NO then the alternative is to to model the rules in code keeping below in mind

  • encapsulate 1 business rule in its own class so that it can be independently tested, customized and updated
  • name the rule the way business mentions it (ubiquitous language)
  • Learn about the specifiation pattern (domain driven design). I think this way of expressing rules is very intuitive and explicit

E.g. copied from here

EligibleForDiscountSpecification isEligibleForDiscountRule = new EligibleForDiscountSpecification();
isEligibleForDiscountRule .IsSatisfiedBy(customer)
是伱的 2024-10-14 14:40:22

业务规则最佳实践指出,规则应该是可插入组件。极简主义方法包括将它们编码在专用库中,然后进行依赖注入或反射...也许您也应该研究契约驱动开发,并查看 www.businessrulesgroup.org/brmanifesto.htm 开始。

Business Rules best practices state that the rules should be pluggable components. A minimalist approach would consist in coding them in a dedicated library, and proceed with Dependency Injection, or Reflection... Maybe you should investigate about Contracts Driven Development too, and look at www.businessrulesgroup.org/brmanifesto.htm to begin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文