a.数组规划问题:

case:
 1. 最原始的方式设置
           public static $first_start = '2011-07-11';
           public static $first_end = '2011-08-21';
           public static $second_start = '2011-08-21';
           public static $second_end = '2011-08-31';
           public static $third_start = '2011-08-31';
           public static $third_end = '2011-10-03';
2.数组概括
    public static $all_time = array(
                "first_start" => "2011-07-11",
                "first_end" => "2011-08-21",
                "second_start" => "2011-08-21",
                "second_end" => "2011-08-31",
                "third_start" => "2011-08-31",
                "third_end" => "2011-10-03"
                 );
3.数组层级概括
    public static $all_time = array(
                "first" => array (
                        "start"=>"20110711",
                        "end"=>"20110821",
                        ),
                "second" => array (
                        "start"=>"20110821",
                        "end"=>"20110831",
                        ),
                "third" => array (
                        "start"=>"20110831",
                        "end"=>"20111003",
                        ),
 
总结:这段代码时昨天出来的总结,但做的还不够好.
      1.变量定义换乱。
      2.变量定义用数组定义稍好,但不体现层次关系
      3.根据需求,体现功能,接近完善。
 
b.代码的严谨性,效率性,封装性:
case:
1.原始代码
public static function getPromoType()
{
    $now = time();
if ($now > strtotime(self::$all_time["first_start"]) && $now <= strtotime(self::$all_time["first_end"])) {
    $type = 1;
}
if ($now > strtotime(self::$all_time["third_start"]) && $now < strtotime(self::$all_time["third_end"])) {
    $type = 2;
    return $type;
}
 
2.第一次修改效果 (strtotime 执行效率 和 次数)
public static function getPromoType()
{
    $now = time();
    $now = date("Y-m-d", $now);
if ($now > self::$all_time["first_start"] && $now <= self::$all_time["first_end"]) {
    $type = 1;
}
if ($now > self::$all_time["third_start"] && $now < self::$all_time["third_end"]) {
    $type = 2;
    return $type;
}
 
3.第二次修改效果
public static function getPromoType()
{
    $type = 0;
    if (PromoUtil::isInTimeSpan(self::$all_time["first"])) {
        $type = 1;
    }
    if (PromoUtil::isInTimeSpan(self::$all_time["third"])) {
        $type = 2;
    }
    return $type;
}
 
PromoUtil类方法:
public static function isInTimeSpan($time_span, $current_date = null)
    {
        if (!$time_span) {
            return false; 
        }
        $ret = false;
        if (!$current_date) {
            $current_date = date("Y-m-d");
        } 
        if ($current_date >= $time_span['start'] && $current_date <= $time_span['end']) {
            $ret = true;
        } 
        return $ret;
    }
 
 
总结:1.能实现功能,但效率低,重复次数多。
      2.效率稍高,但多次调用重写次数多,考虑公共类方法的问题。
      3.公共类封装公共功能,减少代码的冗余,带来代码的精简。
 
感慨:
     代码就是不断地完善,不断的优化.不断的推翻以前的想法。