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 閱讀(194) 評(píng)論(0)  編輯  收藏 所屬分類: refactoring-從地獄中重生
          主站蜘蛛池模板: 赫章县| 象山县| 宝坻区| 潍坊市| 湖州市| 扎鲁特旗| 罗平县| 怀宁县| 枣阳市| 哈巴河县| 东阿县| 焦作市| 桓台县| 图们市| 旌德县| 邹城市| 武强县| 和龙市| 博湖县| 灵台县| 新龙县| 万年县| 西藏| 富顺县| 登封市| 巴林左旗| 资中县| 阿勒泰市| 兖州市| 平塘县| 昌图县| 日照市| 会泽县| 台东县| 巨鹿县| 颍上县| 龙泉市| 肥东县| 无棣县| 嘉祥县| 长汀县|