欢迎来到天天文库
浏览记录
ID:52110652
大小:1.57 MB
页数:17页
时间:2020-03-31
《《重构既有代码》PPT课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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(t
2、emp);doubleperimeter=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())
3、;newRule->SetBeginCycle(oldRule->GetBeginCycle()+1);newRule->SetEndCycle(oldRule->GetEndCycle());newRule->SetMainAcctAmount(oldRule->GetMainAcctAmount());newRule->SetGiftAcctAmount(oldRule->GetGiftAcctAmount());newRule->SetValidDays(0);newRule->SetGiftAcct(oldRule->GetGiftAcct());rule
4、s->Add(newRule);ColdRule*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(
5、oldRule.GetEndCycle());newRule->SetMainAcctAmount(oldRule.GetMainAcctAmount());newRule->SetGiftAcctAmount(oldRule.GetGiftAcctAmount());newRule->SetValidDays(0);newRule->SetGiftAcct(oldRule.GetGiftAcct());returnnewRule;}…..rules->Add(CreateNewRule(*oldRule));引入解释性变量booleanisMacOs=platf
6、orm.toUpperCase().indexOf("MAC")>-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)&&wasIni
7、tialized()&&resize>0){//dosomething}去除双重否定if(!item.isNotFound()){………}if(item.isFound()){……….}使用否定函数if(item.isFound()==false){………}if(item.isNotFound()){……….}自注释voidprintOwing(){//printbannerSystem.out.println(“*********”);System.out.println(“Banner”);System.out.println(“*********”);//p
8、rintd
此文档下载收益归作者所有