Decision model and notation (DMN) is a nice way to model policies and make sure your business rules are implemented properly. Opposite to traditional approach in business rules which was the focus on the rules them selves, in DMN we start from decisions.
Let’s work on a tangible example. In an employees benefits and entitlement system, you would have many rules, which some of them are related to calculate the employee Vacation Days. For example let’s say your company has the following policy:
Every employee receives at least 22 days. Additional days are provided to the following criteria:
1. Only employees younger than 18 or at least 60 years, or employees with at least 30 years of service will receive 5 extra days.
2. Employees with at least 30 days of service and also employees of age 60 or more, receive 3 extra days, on top of the possible additional days already given.
3. If an employee has at least 15 but less than 30 years of service, 2 extra days are give. These 2 days are also provided for employees of age 45 or more. These 2 extra days cannot be combined with the 5 extra days.
(* The policy example was provided by Prof. Jan Vanthienen)
Now let’s have a look at the bellow model:
Each of the blue rectangles are called “Decision” and each line with arrow shows the dependency of each decision to another or to an input data (employee in round rectangle with pink color).
Now we need to build couple of simple decision tables. And then associate each of them to appropriate decision node in the above decision requirement diagram.
Base days
Every employee receives at least 22 days.
Base days
Extra 3 Days rules
Employees with at least 30 days of service and also employees of age 60 or more, receive 3 extra days, on top of the possible additional days already given.
Extra 3 days vacation
Extra 5 days rules
Only employees younger than 18 or at least 60 years, or employees with at least 30 years of service will receive 5 extra days.
Extra 5 days vacation
Extra 2 Days rules
If an employee has at least 15 but less than 30 years of service, 2 extra days are give. These 2 days are also provided for employees of age 45 or more.
These 2 extra days cannot be combined with the 5 extra days. (This part is handled where we add up all the values in Total vacation days)
Extra 2 days eligibility
Total vacation days calculation
In the upper left side decision, we calculate the total days based on eligibility for base days and extra days:
Total vacation days based on other decision tables
We also set the last table aggregation method to Sum based on Rules Order. So the result will be sum of the last column (Vacation Days).
Decision model and Notation defines couple of standard aggregation functions.
Benefits of this Approach
If you model only the Decision Tables, for a slightly more complex policy you will loose the big picture and will have no clue about the whole policy not scenario that is covered. But by using the Decision Model and Notation (DMN), you start from top, and then drill down to each decision implementation (Decision tables) or other types of logic.