Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are table-driven methods?

What is a "table-driven method"?

As mentioned by Bill Gates in the second Windows Vista commercial at 1:05.

like image 963
Jonathan Avatar asked Sep 19 '08 20:09

Jonathan


2 Answers

A table-driven method is quite simple. Use 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] = process_tv_records
hash[cable] = process_cable_records

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, investigate the Fitnesse testing framework at http://fitnesse.org/.

like image 72
David Medinets Avatar answered Oct 08 '22 07:10

David Medinets


Table-driven methods are schemes that allow you to look up information in a table rather than using logic statements (i.e. case, if). In simple cases, it's quicker and easier to use logic statements, but as the logic chain becomes more complex, table-driven code is simpler than complicated logic, easier to modify and more efficient.

Reference: McConnell, Steve. Code Complete, Second Edition. Redmond (Washington): Microsoft, 2004. Print. Page 411, Paragraph 1.

like image 25
Rosellyne Worrall Avatar answered Oct 08 '22 07:10

Rosellyne Worrall