欢迎来到天天文库
浏览记录
ID:20251801
大小:1.57 MB
页数:17页
时间:2018-10-11
《重构既有代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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
此文档下载收益归作者所有