ivaneeo's blog

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

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
          范例(Examples)
          下面是Account class的部分代碼:
          class Account...
              private AccountType _type;
              private double _interestRate;
              double interestForAmount_days(double amount, int days) {
                 return _interestRate * amount * days / 365;
              }
          我想把表示利率的_interestRate搬移到AccountType class去。目前已有數(shù)個(gè)函數(shù)引用了它,interestForAmount_days()就是其一。下一步我要在AccountType中建立_interestRate field以及相應(yīng)的訪問(wèn)函數(shù):
          class AccountType...
              private double _interestRate;

              void setInterestRate(double arg) {
                 _interestRate = arg;
              }
              double getInterestRate() {
                 return _interestRate;
              }

          這時(shí)候我可以編譯新的 AccountType class。
          現(xiàn)在,我需要讓Account class中訪問(wèn)_interestRate field的函數(shù)轉(zhuǎn)而使用AccountType對(duì)象,然后刪除Account class中的_interestRate field。我必須刪除source field,才能保證其訪問(wèn)函數(shù)的確改變了操作對(duì)象,因?yàn)榫幾g器會(huì)幫我指出未正確獲得修改的函數(shù)。
              private double _interestRate;
              double interestForAmount_days(double amount, int days) {
                 return _type.getInterestRate() * amount * days / 365;
              }
          posted on 2005-08-30 14:46 ivaneeo 閱讀(193) 評(píng)論(0)  編輯  收藏 所屬分類: refactoring-從地獄中重生
          主站蜘蛛池模板: 乌鲁木齐市| 岐山县| 宁明县| 冷水江市| 龙门县| 黔南| 安义县| 武冈市| 崇礼县| 广丰县| 新龙县| 甘孜县| 汕尾市| 麻城市| 鸡西市| 黑山县| 双鸭山市| 阳城县| 峨边| 虎林市| 宜君县| 兴宁市| 静海县| 通渭县| 泸州市| 盱眙县| 合水县| 兴国县| 玛纳斯县| 新宁县| 剑川县| 辽阳市| 荆门市| 岳普湖县| 莱阳市| 古蔺县| 江口县| 沙雅县| 新竹市| 平罗县| 宕昌县|