<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ivaneeo's blog

    自由的力量,自由的生活。

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
    范例(Examples)
    class Account...
        int gamma(int inputVal, int quantity, int yearToDate) {
           int importantValue1 = (inputVal * quantity) + delta();
           int importantValue2 = (inputVal * yearToDate) + 100;
           if((yearToDate - importantValue1) > 100)
              importantValue2 -= 20;
           int importantValue3 = importantValue2 * 7;
           //   and so on.
           return importantValue3 -2 * importantValue1;
        }

    為了把這個函數(shù)變成一個函數(shù)對象(method object),我首先需要聲明一個新class。在此新class中我應(yīng)該提供一個final值域用以保存原先對象(源對象):對于函數(shù)的每一個參數(shù)和每一個臨時(shí)變量,也以一個個值域逐一保存。
    class Gamma...
        private final Account _account;
        private int inputVal;
        private int quantity;
        private int yearToDate;
        private int importantValue1;
        private int importantValue2;
        private int importantValue3;

    接下來,加入一個構(gòu)造函數(shù):

    Gamma (Account source, int inputValArg, int quantityArg, int yearToDateArg) {
        _account = source;
        inputVal = inputValArg;
        quantity = quantityArg;
        yearToDate = yearToDateArg;
    }

    現(xiàn)在可以把原來的函數(shù)搬到compute()了。函數(shù)中任何調(diào)用Account class的地方,我都必須改而使用_account值域:
    int compute() {
           int importantValue1 = (inputVal * quantity) + _account.delta();
           int importantValue2 = (inputVal * yearToDate) + 100;
           if((yearToDate - importantValue1) > 100)
              importantValue2 -= 20;
           int importantValue3 = importantValue2 * 7;
           //   and so on.
           return importantValue3 -2 * importantValue1;
    }
    然后,我修改舊函數(shù),讓它將它的工作轉(zhuǎn)發(fā)給剛完成的這個函數(shù)對象(method object):
    int gamma(int inputVal, int quantity, int yearToDate) {
        return new Gamma(this, inputVal, quantity, yearToDate).compute();
    }
    這就是本項(xiàng)重構(gòu)的基本原則。它帶來的好處是:現(xiàn)在我可以輕松地對compute()函數(shù)采取Extract Method(110),不必?fù)?dān)心引數(shù)(argument)傳遞。
    int compute() {
        int importantValue1 = (inputVal * quantity) + _account.delta();
           int importantValue2 = (inputVal * yearToDate) + 100;
           importantThing();
           int importantValue3 = importantValue2 * 7;
           //   and so on.
           return importantValue3 -2 * importantValue1;
    }
    void importantThing() {
        if((yearToDate - importantValue1) > 100)
           importantValue2 -= 20;
    }
    posted on 2005-08-29 16:49 ivaneeo 閱讀(259) 評論(0)  編輯  收藏 所屬分類: refactoring-從地獄中重生
    主站蜘蛛池模板: 青娱乐免费在线视频| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 亚洲综合网站色欲色欲| 1区1区3区4区产品亚洲| 亚洲熟女精品中文字幕| 久久免费99精品国产自在现线| 亚欧人成精品免费观看| 亚洲日韩精品无码专区网站| 美女视频黄视大全视频免费的| 无码AV片在线观看免费| 日韩亚洲精品福利| 激情综合亚洲色婷婷五月| 伊人免费在线观看高清版| 免费网站看v片在线香蕉| 亚洲中文字幕无码爆乳av中文 | 亚洲欧美熟妇综合久久久久 | 亚洲免费在线观看| 成年美女黄网站18禁免费| 亚洲AV综合色区无码一区| 在线观看亚洲精品专区| 国产电影午夜成年免费视频| 中文字幕亚洲无线码a| 成人免费区一区二区三区| 免费在线观看视频a| 亚洲欧美国产日韩av野草社区| 成年在线网站免费观看无广告| 综合偷自拍亚洲乱中文字幕| 在线观看特色大片免费视频 | 亚洲综合精品第一页| 四虎在线播放免费永久视频| 精品日韩99亚洲的在线发布| 国产无遮挡吃胸膜奶免费看| 亚洲人成人无码.www石榴 | 99精品视频免费观看| 亚洲国产另类久久久精品小说| 免费一区二区三区在线视频| 国产色爽免费视频| 在线观看人成视频免费无遮挡| 亚洲国产中文在线视频| 久草视频免费在线观看| 成年免费a级毛片|