特定時間段有效的業務規則——如何有序管理 (Business rules that are valid for specific time span – how to manage in an orderly manner)


問題描述

特定時間段有效的業務規則——如何有序管理 (Business rules that are valid for specific time span – how to manage in an orderly manner)

I just started working for a government agency and I have come across an interesting problem: business rules depend on legislature and as such they have to respect the exact time periods that legislature has been active. 

To give you an example, if a subject has applied for a subsidy on a certain date, than he has to be evaluated according to criteria that vas valid on that given date. That same subsidy, for someone that applied on some later date has different criteria. I was wondering if there is a known pattern to deal with these time-dependent rules in orderly fashion. At the moment, the code is sprinkled with expressions akin to:

if application.date >”July 17th, 2008”

What is the best way to manage this problem?


參考解法

方法 1:

This looks like a case for Chain of Responsibility. You would have handlers for each legislature. You pass the application to the most recent handler first. If it is too old, it passes it down to the handler for the previous legislature.

方法 2:

You can use a few patterns. For example using the temporal property pattern you can create on object which contains business rules which are active at a certain point in time. Also, using the specification pattern you can create business rules which are effective based on a certain date. You can associate an effective date range with each policy so that the decision of whether a given policy applies can be made. The book Analysis Patterns contains many patterns that could be applicable in your scenario.

EDIT: I meant to link to the temporal object pattern instead of temporal property. This may shed some light on implementing the database mapping.

方法 3:

If the rules are complex you may need a (business) rules engine. I don't know what implementations exist for your platform, but for Java the typical choice is Drools and its Expert subproject. It defines domain-specific language for defining rules. Note that it might have an interface for non-java users.

Otherwise you may try something like the Strategy pattern - you have a list of strategies with two methods appliesTo(date) and handle(data). You iterate the list and if a strategy is applicable to a date - let it handle the data.

方法 4:

At the architecture level, there are two approaches to solve this problem.

The first is to ETL the data to your Warehouse before the business logic is applied against the data. I prefer this approach.

Sometimes though, it's not possible to do this--i.e., the business logic is applied against the data before it is written to the OLTP (the source used to populate the Data Warehouse) so you have no choice. In this instance, this problem is usually referred to as a rapidly changing dimension problem. (My assumption here is that the data referred to in your question is stored in a Dimension Table rather than a Fact Table).

There is a vast body of commentary on this subject available on the Web. Among these sources, i recommend any of the articles (free) or books (not free) by Ralph Kimball.

The best way to reconcile a rapidly changing dimension is almost certainly fact specific; still, perhaps the most common technique is to c*reate a new dimension table* that stores the data applied against the new business logic. In other words, you would have in your DW schema a separate dimension table for for each business rule.

(by DanBjörn PollexeulerfxBozhodoug)

參考文件

  1. Business rules that are valid for specific time span – how to manage in an orderly manner (CC BY-SA 3.0/4.0)

#ooad #business-rules #OOP #design-patterns






相關問題

接口實現是否應該獨立 (Should Interface implementations be independent)

當我們有不同的回報類型時實現策略模式 (Achieve strategy pattern when we have different return type)

抽象VS信息隱藏VS封裝 (Abstraction VS Information Hiding VS Encapsulation)

應用程序中jQuery表單綁定代碼的最佳實踐 (Best practices with jQuery form binding code in an application)

耦合與內聚 (Coupling and cohesion)

什麼時候應該在C ++中使用類與結構? (When should you use a class vs a struct in C++?)

What is an anti-pattern? (What is an anti-pattern?)

如何根據編程代碼顯示聚合? (How to Show Aggregation in terms of A Programming Code?)

協調 MVP 三元組 (Coordinating MVP triads)

裝飾器和虛擬方法 (Decorators and Virtual Methods)

設計和建築有什麼區別? (What is the difference between Design and Architecture?)

特定時間段有效的業務規則——如何有序管理 (Business rules that are valid for specific time span – how to manage in an orderly manner)







留言討論