tags:

views:

811

answers:

4

I learned some time ago about Decision Trees and Decision tables. I feel that Decision Tables can help with conditional If-Then-Else statements. In particular, I feel that Decision Tables have no side-effects, for example, if you didn't notice that you need one more "else if" statement.

But I am not sure how I can implement it. Arrays? Database Tables? Does anyone even use Decision Tables in their code, nowadays?

+1  A: 

I would highly recommend chapter 18 of Code Complete.

You could also check this post What Are Table Driven Methods

EBGreen
A: 

Well, I did my own research :S

  1. This is something from IBM about decision tables used to make testing scenarios
  2. This is from a company that makes decision tables that are then translated to if-then-else statements in vb.net.
  3. Open source ruby workflow and bpm engine that uses decision tables.

So, I am still looking. If anyone has some good answers, please enter them in.

Jonathan
A: 

A table-driven method uses data structures instead of if-then statements to drive program logic. For example, if you are processing two types of records (tv versus cable) you might do this:

hash[tv] = processTvRecords

hash[cable] = processCableRecords

In some languages, like Ruby or Perl, this technique is straightforward. In Java, you'd need to use Reflection to find method handles.

If you want to learn about decision tables, investiagethe Fitnesse testing framework at http://fitnesse.org/.

David Medinets
A: 

By far the best implementation I've seen for decision tables is an application called Prologa, which is available for download at http://www.econ.kuleuven.be/prologa. Unfortunately, it's only available in Windows, and there can be a short delay while you wait for the evaluation key.

The software handles conditions that are non-binary, can collapse similar rules, and actually tracks the number of combinations that your table currently covers so it's great for completeness checks for particularly large tables. Also handles nested tables gracefully (where the result of one table can be the condition of another table).

mdy