摘要:
代码中如果有范围参数: public void GetInfo(datetime beginTime,datetime endTime){ if(beginTime>'2012-01-01'&& endTime<'2012-12-30'){ //处理代码 } else{ //处理代码 } } 重构方式:封装时间范围。 public class DateRange{ public datet... 阅读全文
随笔档案-2012年08月
代码重构-异常处理
2012-08-28 16:51 by Spring.Guo, 625 阅读, 收藏,
摘要:
按照产生异常的原因是否明确,来区分异常的处理方式。避免在代码中全部用try-catch 去检测,甚至使用多重try-catch嵌套处理。 异常明确,可以检测。 比如取钱,很显然输入的取钱金额不能大于余额(信用卡不在考虑之列),这种错误是可以检测的,可排除的。 public void Withdraw (decmal amount){ if(amount>_balance){ throw new... 阅读全文
浙公网安备 33010602011771号