<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                **摘要:**由于最近在做重構的項目,所以對重構又重新進行了一遍學習和整理,對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)查看原文。 **概念:**本文中的“封裝條件”是指條件關系比較復雜時,代碼的可讀性會比較差,所以這時我們應當根據條件表達式是否需要參數將條件表達式提取成可讀性更好的屬性或者方法,如果條件表達式不需要參數則可以提取成屬性,如果條件表達式需要參數則可以提取成方法。 **正文:**如下代碼所示,PerformCoolFunction里面的if條件判斷比較復雜,看起來有點雜亂,所以就把它提出來。 ~~~ using System;namespace LosTechies.DaysOfRefactoring.EncapsulateConditional.Before{ public class RemoteControl { private string[] Functions { get; set; } private string Name { get; set; } private int CreatedYear { get; set; } public string PerformCoolFunction(string buttonPressed) { // Determine if we are controlling some extra function // that requires special conditions if (Functions.Length > 1 && Name == "RCA" && CreatedYear > DateTime.Now.Year - 2) return "doSomething"; } }} ~~~ 如下代碼所示,我們把條件表達式封裝成HasExtraFunctions屬性,這樣先前的條件判斷就成了if (HasExtraFunctions) ,所以這樣就在很大程度上提高了可讀性。 ~~~ using System;namespace LosTechies.DaysOfRefactoring.EncapsulateConditional.After{ public class RemoteControl { private string[] Functions { get; set; } private string Name { get; set; } private int CreatedYear { get; set; } private bool HasExtraFunctions { get { return Functions.Length > 1 && Name == "RCA" && CreatedYear > DateTime.Now.Year - 2; } } public string PerformCoolFunction(string buttonPressed) { // Determine if we are controlling some extra function // that requires special conditions if (HasExtraFunctions) return "doSomething"; } }} ~~~ **總結:**這個重構在很大程度上能改善代碼的可讀性,尤其是在一個邏輯很復雜的應用中,把這些條件判斷封裝成一個有意義的名字,這樣很復雜的邏輯也會立刻變得簡單起來。
                  <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>

                              哎呀哎呀视频在线观看