Search code examples
oopdesign-patternsbusiness-rulesooad

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?


Solution

  • 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.