- 1、本文档共17页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
重构既有代码.ppt
坏味道 public int discount( int price ) { if( price 1000) { price -= 20; …….. } return price; } public int discount( final int price ) { int ret = price; if( price 1000) { ret -= 20; …….. } return ret ; } 传值参数不能用赋值,职责不明确,应用创建临时变量对其操作 坏味道 double temp = 2 * (_height + _width); System.out.println (temp); temp = _height * _width; System.out.println (temp); double perimeter = 2 * (_height + _width); System.out.println (perimeter); double area = _height * _width; System.out.println (area); 职责不明确 ColdRule *newRule = new ColdRule(); newRule-SetOID(oldRule-GetOID()); newRule-SetRegion(oldRule-GetRegion()); newRule-SetRebateRuleID(oldRule-GetRebateRuleID()); newRule-SetBeginCycle(oldRule-GetBeginCycle() + 1); newRule-SetEndCycle(oldRule-GetEndCycle()); newRule-SetMainAcctAmount(oldRule-GetMainAcctAmount()); newRule-SetGiftAcctAmount(oldRule-GetGiftAcctAmoun t()); newRule-SetValidDays(0); newRule-SetGiftAcct(oldRule-GetGiftAcct()); rules-Add(newRule); ColdRule* CreateNewRule(ColdRule oldRule) { ColdRule *newRule = new ColdRule(); newRule-SetOID(oldRule.GetOID()); newRule-SetRegion(oldRule.GetRegion()); newRule-SetRebateRuleID(oldRule.GetRebateRuleID()); newRule-SetBeginCycle(oldRule.GetBeginCycle() + 1); newRule-SetEndCycle(oldRule.GetEndCycle()); newRule-SetMainAcctAmount(oldRule.GetMainAcctAmount()); newRule-SetGiftAcctAmount(oldRule.GetGiftAcctAmount()); newRule-SetValidDays(0); newRule-SetGiftAcct(oldRule.GetGiftAcct()); return newRule; } ….. rules-Add(CreateNewRule(*oldRule)); 引入解释性变量 boolean isMacOs = platform.toUpperCase().indexOf(MAC) -1; boolean isIEBrowser = browser.toUpperCase().indexOf(IE) -1; boolean wasResized = resize 0; if (isMacOs isIEBrowser wasInitialized() wasResized) { // do something } if ( (platform.toUpperCase().indexOf(MAC) -1) (browser.toUpperCase().indexOf(IE) -1) wasInitialized() resize 0 ) { // do some
您可能关注的文档
- 通信线路定额.xls
- 通信设施建设建设工程管理中怠于行使权利风险.doc
- 通心络健康讲座.ppt
- 通泰扬届高三第三次调研测试数学试题三模.doc
- 通用型号对照.xls
- 通用年结存.ppt
- 通用挽联.doc
- 通用挽联集锦.doc
- 通用材方管-角铝-槽铝-扁铝)-P-.xls
- 通用材方管-角铝-槽铝-扁铝-P-.xls
- 2023咸阳职业技术学院招聘笔试真题参考答案详解.docx
- 2023四川化工职业技术学院招聘笔试真题及参考答案详解.docx
- 2023哈尔滨职业技术学院招聘笔试真题及参考答案详解.docx
- 2023商洛职业技术学院招聘笔试真题及答案详解1套.docx
- 2023呼伦贝尔职业技术学院招聘笔试真题参考答案详解.docx
- 2023南阳农业职业学院招聘笔试真题参考答案详解.docx
- 2023天津公安警官职业学院招聘笔试真题带答案详解.docx
- 2023年上海电机学院招聘笔试真题参考答案详解.docx
- 2023年四川艺术职业学院招聘笔试真题参考答案详解.docx
- 2023安徽体育运动职业技术学院招聘笔试真题及答案详解一套.docx
文档评论(0)