什么是表驱动方法

时间:2020-03-06 14:27:43  来源:igfitidea点击:

比尔·盖茨(Bill Gates)在http://www.youtube.com/watch上的Vista商业版上提到的表驱动方法是什么?v = gBWPf1BWtkw

解决方案

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.

参考:麦康奈尔,史蒂夫。代码完整,第二版。雷德蒙德(华盛顿):微软,2004年。印刷。页411,第1段。

表驱动的方法非常简单。使用数据结构而不是if-then语句来驱动程序逻辑。例如,如果我们要处理两种类型的记录(电视与电缆),则可以这样做:

hash[tv] = process_tv_records
hash[cable] = process_cable_records

在某些语言(如Ruby或者Perl)中,此技术非常简单。在Java中,我们需要使用Reflection查找方法句柄。

如果我们想了解决策表,请访问http://fitnesse.org/上的Fitnesse测试框架。