标签:style class blog code java http
一种scheme,用表来做信息存取,代替逻辑语句(if/else)
简化逻辑语句,避免大量嵌套的 if/else 或者 switch/case
三种访问表的方式
// get the full name of weekday // good String[] weekdays = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; String getName(int day) { return weekdays[day]; } // bad String getName(int day) { switch (day) { case 0: return "Sunday"; break; case 1: return "Monday"; break; // and so on } }
《Code Complete》ch.18 表驱动法,布布扣,bubuko.com
标签:style class blog code java http
原文地址:http://www.cnblogs.com/maozhige/p/3782383.html