重构既有代码

重构既有代码

ID:20251801

大小:1.57 MB

页数:17页

时间:2018-10-11

重构既有代码_第1页
重构既有代码_第2页
重构既有代码_第3页
重构既有代码_第4页
重构既有代码_第5页
资源描述:

《重构既有代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、坏味道publicintdiscount(intprice){if(price>1000){price-=20;……..}returnprice;}publicintdiscount(finalintprice){intret=price;if(price>1000){ret-=20;……..}returnret;}传值参数不能用赋值,职责不明确,应用创建临时变量对其操作坏味道doubletemp=2*(_height+_width);System.out.println(temp);temp=_height*_width;System.out.println(temp);d

2、oubleperimeter=2*(_height+_width);System.out.println(perimeter);doublearea=_height*_width;System.out.println(area);职责不明确ColdRule*newRule=newColdRule();newRule->SetOID(oldRule->GetOID());newRule->SetRegion(oldRule->GetRegion());newRule->SetRebateRuleID(oldRule->GetRebateRuleID());newRule->Se

3、tBeginCycle(oldRule->GetBeginCycle()+1);newRule->SetEndCycle(oldRule->GetEndCycle());newRule->SetMainAcctAmount(oldRule->GetMainAcctAmount());newRule->SetGiftAcctAmount(oldRule->GetGiftAcctAmount());newRule->SetValidDays(0);newRule->SetGiftAcct(oldRule->GetGiftAcct());rules->Add(newRule);Co

4、ldRule*CreateNewRule(ColdRule&oldRule){ColdRule*newRule=newColdRule();newRule->SetOID(oldRule.GetOID());newRule->SetRegion(oldRule.GetRegion());newRule->SetRebateRuleID(oldRule.GetRebateRuleID());newRule->SetBeginCycle(oldRule.GetBeginCycle()+1);newRule->SetEndCycle(oldRule.GetEndCycle());n

5、ewRule->SetMainAcctAmount(oldRule.GetMainAcctAmount());newRule->SetGiftAcctAmount(oldRule.GetGiftAcctAmount());newRule->SetValidDays(0);newRule->SetGiftAcct(oldRule.GetGiftAcct());returnnewRule;}…..rules->Add(CreateNewRule(*oldRule));引入解释性变量booleanisMacOs=platform.toUpperCase().indexOf("MAC

6、")>-1;booleanisIEBrowser=browser.toUpperCase().indexOf("IE")>-1;booleanwasResized=resize>0;if(isMacOs&&isIEBrowser&&wasInitialized()&&wasResized){//dosomething}if((platform.toUpperCase().indexOf("MAC")>-1)&&(browser.toUpperCase().indexOf("IE")>-1)&&wasInitialized()&&resize>0){//dosomething}

7、去除双重否定if(!item.isNotFound()){………}if(item.isFound()){……….}使用否定函数if(item.isFound()==false){………}if(item.isNotFound()){……….}自注释voidprintOwing(){//printbannerSystem.out.println(“*********”);System.out.println(“Banner”);System.out.println(“*********”);//printd

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。