<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                **摘要:**由于最近在做重構的項目,所以對重構又重新進行了一遍學習和整理,對31天重構最早接觸是在2009年10月份,由于當時沒有訂閱[Sean Chambers](http://www.lostechies.com/blogs/sean_chambers/archive/2009/07/31/31-days-of-refactoring.aspx)的blog,所以是在國外的社區上閑逛的時候鏈接過去的。記得當時一口氣看完了整個系列并沒有多少感覺,因為這些基本上項目都在使用,只是我們沒有專門把它標示和整理出來,所以也沒有引起多大的重視。現在突然接手這個重構項目,由于團隊成員技術和經驗參差不齊,所以有必要專門整理一個重構的綱要,當然這個系列也非常適合做新系統的代碼規范參考,只要有代碼的地方,這個重構規范就很有價值。周末也不想出去閑逛,因為在剛到這個美麗的城市,沒有親戚或者朋友,所以才能靜下心來兩天時間寫完這個重構參考規范。同時也感受了Windows Live writer寫文章的快感。當然重構的整體架構得另當別論(整體架構在我的這篇文章有專門的講解([http://www.cnblogs.com/zenghongliang/archive/2010/06/23/1763438.html](http://www.cnblogs.com/zenghongliang/archive/2010/06/archive/2010/06/23/1763438.html))。大的架構設計好了以后,這些重構細節點就成了東風之后的大火,對整個項目也是至關重要。31天重構這個系列和《代碼大全》、《重構:改善既有代碼的設計》比較起來最大的特點就是比較簡單、淺顯易懂。那么我這些文章也都是學習Sean Chambers的31天重構的筆記整理,所以如果大家對這個筆記有任何異議也可以指出。 具體也可以通過[http://www.lostechies.com/blogs/sean_chambers/archive/2009/07/31/31-days-of-refactoring.aspx](http://www.lostechies.com/blogs/sean_chambers/archive/2009/07/31/31-days-of-refactoring.aspx)查看原文。 **概念:**本文所講的移動方法就是方法放在合適的位置(通常指放在合適的類中)。 **正文:**移動方法是一個很簡單也很常見的重構,只要是系統就會存在很多類,那么類里面包括很多方法,如果一個方法經常被另外一個類使用(比本身的類使用還多)或者這個方法本身就不應該放在這個類里面,那么這個適合應該考慮把它移到合適的類中。代碼如下: ~~~ namespace LosTechies.DaysOfRefactoring.MoveMethod.Before{ public class BankAccount { public BankAccount(int accountAge, int creditScore, AccountInterest accountInterest) { AccountAge = accountAge; CreditScore = creditScore; AccountInterest = accountInterest; }? public int AccountAge { get; private set; } public int CreditScore { get; private set; } public AccountInterest AccountInterest { get; private set; } public double CalculateInterestRate() { if (CreditScore > 800) return 0.02; if (AccountAge > 10) return 0.03; return 0.05; } } public class AccountInterest { public BankAccount Account { get; private set; } public AccountInterest(BankAccount account) { Account = account; } public double InterestRate { get { return Account.CalculateInterestRate(); } } public bool IntroductoryRate { get { return Account.CalculateInterestRate() < 0.05; } } }} ~~~ 移動以后大家可以看到BankAccount類的職責也單一,同時CalculateInterestRate也放到了經常使用且適合它的類中了,所以此重構是一個比較好的重構,能讓整個代碼變得更加合理。 ~~~ namespace LosTechies.DaysOfRefactoring.MoveMethod.After{ public class AccountInterest { public BankAccount Account { get; private set; } public AccountInterest(BankAccount account) { Account = account; } public double InterestRate { get { return CalculateInterestRate(); } } public bool IntroductoryRate { get { return CalculateInterestRate() < 0.05; } } public double CalculateInterestRate() { if (Account.CreditScore > 800) return 0.02; if (Account.AccountAge > 10) return 0.03; return 0.05; } }} ~~~ [](http://11011.net/software/vspaste) ~~~ namespace LosTechies.DaysOfRefactoring.MoveMethod.After{ public class BankAccount { public BankAccount(int accountAge, int creditScore, AccountInterest accountInterest) { AccountAge = accountAge; CreditScore = creditScore; AccountInterest = accountInterest; } public int AccountAge { get; private set; } public int CreditScore { get; private set; } public AccountInterest AccountInterest { get; private set; } }} ~~~ **總結:**這個重構法則在很多時候能讓我們把代碼組織的結構調整得更合理,同時也能給以后的維護帶來方便。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看