Simplify programs by using decision tables

VocExile/Programming Topics/Decision Tables

Decision Tables

Consider the following programming task:

Your program contains two variables, A and B. Each variable can have a value of 0 to 4. Each combination of values of A and B will require that a different operation must be performed. There are eight possible operations. For instance, if A and B both equal zero, Module 1 is executed, if A equals 0 and B equals 1, Module 2 is executed, etc. Which Module is required to be executed can not be determined mathematically because each choice is completely arbitrary.

A second requirement is that every two or three weeks, changes in which modules will be called must be made.

How would you program something like this? There are twenty-five combinations, each one pointing to one of eight modules. Can you imagine what your code would look like if you tried to use IF statements to do this job?.

To simplify your project, you can design a decision table as shown below dimensioned as AB_TABLE(5,5).

Contents of the Variable AB_TABLE(5,5)

For each value of A and B, the computer looks at the table to select the proper module to go to. A single CASE statement can then be used to route control to the proper module. If the choice of module depends on more than just two variables, additional tables could be linked together.

If the values to be tested are larger, a table like this can still be used. Simply multiply by and/or add a correction factor to each variable to give it a value that is within the range of the table. These corrected values would be used to reference the table.

This kind of a system is good because the logic of the program is easy to keep track of and is easily changed. In fact, the program can be designed so that a user can change the contents of the table, and therefore reprogram the application, while it is running.

Decision tables were first used in programming in the late fifties. The web site for the Logitech Company provides a historic overview of decision tables and the software used to create them. Two different commercial programs for generating the code for decision tables are available for download there for a low price

Back to Programming Menu.

Back to Main Menu.


http://www.nfinity.com/~exile/logictab.htm
Email: See bottom of Programming Menu
Date last updated: November 30, 2000