Sunteți pe pagina 1din 11

FlexRule

Flexible Software Made Easy

Modeling Business Logic Decision Table

Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia
Version 1.0

info@pliantframework.com
www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

FlexRule
Flexible Software Made Easy

Introduction
Business logic (i.e. business rules) can be presented visually in different forms. One of a popular ways is called
Decision Table. This is a tabular form consists of all of combinations between conditions and actions (or
conclusions). The benefit of using Decision Table is that many people understands it very well, it structures and
organizes business rules based on a higher level scenario or decision (i.e. question to be answered).

What is a Decision Table?


In a very simple form, a Decision table is a tabular structure (table) that has multiple columns and rows modeling
a business logic (a set of business rules) that represents under what conditions, which actions should be taken.
The conditions and actions can be either be arranged vertically or horizontally.

Horizontal
Inputs

Condition

Condition

Outputs

Condition

Action

Action

Rule

Vertical
Condition
Inputs

Condition
Condition

Outputs

Action
Action
Rule

Either ways, consider the conditions as the input of a decision and the actions as the output of the decision. And
in a Decision Table you map between combinations of inputs to outputs.
Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

FlexRule
Flexible Software Made Easy

Simple Example
Lets consider a simple story. You are purchasing a book from an online store and you received the book after a
while. Now based on your experience you may want to:
1. Refer to a friend
2. Write a complaint
3. Share your positive feedback on social media
As you can see now you have a list of actions based on your experiences for:
1. How was your online ordering system experience? (Awesome/OK/Disaster)
2. Was book delivered on time? (Yes/No)
3. Was delivered book in original condition? (Yes/NO)
Now lets see how we can model scenario as a decision table. In this example what is the question the Decision
Table should answer?

Question: What should I do, when I purchased a book online?


To answer this question, there are 3 easy steps:

Step 1: Understanding the Numbers of Conditions.


To calculate the total possible number of combination you need to just know the possible values for each of the
criteria.

Total Rules = [condition 1`s values] x [condition 2s values] x x [condition 3s values]

So based on this formula, we have: Total Rules = [3 values] x [2 values] x [2 values] = 12 combinations.

Step 2: Building the Decision Table.


First, we create a table with 3 condition columns and 3 action columns, which means in a horizontal decision
table.

Ordering
Experience

Delivery
On time?

Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

Delivered
Condition

Refer
To a
Friend

Write
Complaint

Share
Positive
Feedback

FlexRule
Flexible Software Made Easy

Step 2: Fill Out All Possible Combinations.


This is very similar to populating a truth table, but the difference is each column may have multiple values but
just true and false.
1. Calculate the numbers of total rules from the previous formula
2. Choose your first condition, and divide numbers of rules to the numbers of possible values of this
condition. Put that many of each values of the condition
3. Pick the next condition in the table and repeat until all conditions are finished.
Once youve done that, you have the bellow table:

1
2
3
4
5
6
7
8
9
10
11
12

Ordering
Experience

Delivery
On time?

Delivered
Condition

Awesome
Awesome
Awesome
Awesome
OK
OK
OK
OK
Disaster
Disaster
Disaster
Disaster

Yes
Yes
No
No
Yes
Yes
No
No
Yes
Yes
No
No

Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No

Refer
To a
Friend

Write
Complaint

Share
Positive
Feedback

For example:
1. As you see in the above table, condition column for Ordering Experience has 3 possible values:
Awesome, OK and Disaster. By dividing 12 (total numbers of rules) to 3 (numbers of possible values), we
fill 4 times of each value under the first column.
2. Then we pick the next column Delivery on Time which has 2 values, and we divide result of the
previous step (4) to 2. Which means we fill 2 of each value (true/false).
3. And least, we divide (2) from last step, and divide by numbers of values for Delivered condition which
is 2 and as the result, we fill 1 time for each value on this column.

Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

FlexRule
Flexible Software Made Easy

Step 3: Decide on Actions.


Now simply navigate each row (rule) in the table and tick under an action you want to take based on each
circumstances (conditions):

1
2
3
4
5
6
7
8
9
10
11
12

Ordering
Experience

Delivery
On time?

Delivered
Condition

Awesome
Awesome
Awesome
Awesome
OK
OK
OK
OK
Disaster
Disaster
Disaster
Disaster

Yes
Yes
No
No
Yes
Yes
No
No
Yes
Yes
No
No

Yes
No
Yes
No
Yes
No
Yes
No
Yes
No
Yes
No

Refer
To a
Friend

Write
Complaint

Share
Positive
Feedback

As you see now you take decision based on the mix of each conditions on each row, what actions should be
taken. Thats why it is called a Decision Table.

Decision Table Editors


As you saw in the previous section, you really dont need a special editor for a decision table. You can define the
table in a Word document or any spreadsheet (i.e. MS Excel). However, if you use a proper Decision Table editor
like the one comes with FlexRule Designer (http://www.flexrule.com/designer) it has many advantages:
1.
2.
3.
4.
5.
6.

Allows validation of table


Finds rules overlap
Finds conditions missing values
Allows simulating the table by providing set of values
Ability to execute and debug the decision table
Ability to Import from Spreadsheets (i.e. MS Excel, Google Doc)

Input Values (Conditions)


Inputs of conditions in decision table can have different values, and be presented in many forms as expressions.
Each input (cell values on the conditions/input columns) represents a Boolean logic which after evaluation will
have a value of either true or false.
In bellow examples, green columns are inputs or conditions. The actions or outputs columns are in pink or
salmon color.
Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

FlexRule
Flexible Software Made Easy

Simple Values:
Each cell may have a simple value which can be numeric, string, date time, Boolean (true/false). By default if
only value is used in a cell, the equality operator is considers as the binding operator between the value and the
column condition.

For our example, in the A4 cell true is added as the input value of Eligible for Base Days which makes the
binding operator to equal (i.e. == , eq).

Values with Operators:


As you saw in the previous type of value, when there is no operator is presented in the cell values, default is
equal. But lets consider the following decision table for numbers of annual leave an employee is eligible for:

As you see in the above example, the conditions (inputs) are in the green column. And there are values in the
input cells that contains operators e.g. < or > or >= so in this example binding operator between the column
condition and the value is not simply equal but the one that is explicitly used in the input value.

Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

FlexRule
Flexible Software Made Easy

Range Values:
In some more other scenario you can use a range expression as the input value.

As you see in this example cell B5 has a value of [15; 30) which indicates a range value. Which in this example
can be read as Years of Service is between 15 and 30 excluding 30.
For excluding the lower boundary of range you can use ( and for excluding the upper boundary of range use ).
For inclusion values use [ and ] for lower and upper boundary of range.

Empty Values:
When in a rule, a condition is not participating then leave the cell value empty. For example, in previous picture,
in rule number 5, Age is left empty. What that means is that that rules only has one condition which is Years of
Service.

List Values (Multi-Value cell):


When there is a set of values that you want to reference, they can be simply comma split inside a curly bracket.

Value of each element can be references with $ prefix in the column. I.e. $1 refers to 2 and $2 refers to 4.

Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

FlexRule
Flexible Software Made Easy

In the multi-value-cell (List Values) there is no default binding operator. However if existence of a value inside
the list of values need to be tested, the in operator can be used.
In the above example, the B5 condition can be read is Years of Service is equal to either of 2 or 4. What that
means is employee will get 1 extra days leave on 2nd and 4th year of service.

Negate Values:
If the condition in a rule should be used as a negative condition, then not: should be used as the cell value
prefix.
For example in the bellow decision table to calculate the annual leave of an employee, the B7 input value is
negated. Which means is not greater or equal to 10.

Expression Values:
Sometimes, the input values are not just simple values but they are result of an evaluation of an expression
which can reference a variable, or can call a method or access a property of object. In these cases a colon :
should be used as the cell prefix.

Output Values (Actions)


There are also, multiple valid kinds of values can be used as Output or Action cells:
1.
2.
3.
4.
5.

Simple Values
Values with Operators
Empty Values
Expression Values
List Values (Mutli-Value) without in operator

Which their behaviour are very similar to the input (condition) values out their effects are in the action parts or
output values of the decisions.

Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

FlexRule
Flexible Software Made Easy

Please note, the default binding operator in action is assign or set operator which sets an output parameter to a
value. So for example once no operator is used in an output cell, the assign will be used. In the previous example
in C7 cell number 5 is entered in Eligibility Annual Leave (days) cell which means it sets the numbers of days
to 5.

Hit Behaviour
Horizontal Decision Tables are being executed, from top to bottom and left to right. Rules on the top of table
has higher priority on execution.
A Decision Table can be:
1. Single hit: only one rule can meet the criteria for a set of values
2. Multihit: Multiple rules can be activated for a set of values
In Decision Table when Multihit behaviour is used, there are some standard aggregate functions that can be
used:
1.
2.
3.
4.
5.

Collect
Sum
Min
Max
Average

Of you can define your own aggregate function when required.

Advanced Decision Table


Reusability
More often than not, in a complex business scenario, there will be multiple decision tables which they need to
call each other. In order to do that you can
1. Allow a decision table call other decision table by passing values, and retrieving results back (i.e. similar
to a function call)
2. Allow another higher level model manages the interaction between Decision Tables
a. Decision Flow
b. Decision Graph (i.e. Decision Model and Notation Decision Requirement Diagram or DRD)

Priority and Groups


Decision Tables would model set of rules and the priority of rule execution is simple the rules order. However in
some complex scenarios:
1. A custom priority can overrode the rule execution based on order
2. Within a Decision Table itself, rules can be grouped by an identifier (i.e. group name)

Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

FlexRule
Flexible Software Made Easy

These behaviour are discouraged to be used on some standards i.e. Decision Model and Notation (DMN). If you
follow does standards, you should avoid override the priority and grouping rules.

Execution Behaviour
When a rules conditions are satisfied with a set of values, the action of the rules will be executes which can be:
1.
2.
3.
4.
5.

Any method call to any object or services


Setting objects properties and updating values
Applying any aggregation functions (standard or custom)
Adding parameterized notification and messages (Info, warning, Error)
Halting the execution and gracefully exiting the decision table

In C7 cell number 5 is entered in Eligibility Annual Leave (days) cell which means it sets the numbers of days
to 5.

Online Resources
Here are couple of online resources on Decision Table:
1. Learning Decision Table: http://wiki.flexrule.com/index.php?title=Decision_table
2. Modeling Business Policies: http://www.flexrule.com/archives/decision-model-and-notation-policyexample/
3. Validation (conflicts): http://www.flexrule.com/archives/business-rule-conflict/
4. Aggregation functions: http://www.flexrule.com/archives/decision-table-aggregation/
5. And more at http://www.flexrule.com/archives/category/decision-table/

Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

FlexRule
Flexible Software Made Easy

For More Information Please Visit


http://www.flexrule.com

FlexRule
Flexible Softw are Made Easy

Pliant Framework
info@pliantframework.com

www.pliantframework.com
+61-399883994
P.O. Box 1024, Mitcham North, VIC 3132, Australia

S-ar putea să vă placă și