<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國際加速解決方案。 廣告
                ### Inline Class(將類內聯化) 你的某個class沒有做太多事情(沒有承擔足夠責任)。 將class的所有特性搬移到另一個class中,然后移除原class。 ![](https://box.kancloud.cn/2016-08-15_57b1b56c51e5c.gif) **動機(Motivation)** Inline Class正好與Extract Class 相反。如果一個class不再承擔足夠 責任、不再有單獨存在的理由〔這通常是因為此前的重構動作移走了這個class的 責任),我就會挑選這一「萎縮class」的最頻繁用戶(也是個class),以Inline Class手法將「妻縮class」塞進去。 **作法(Mechanics)** - 在absorbing class(合并端的那個class)身上聲明source class的public協議, 并將其中所有函數委托(delegate)至source class。 - 如果「以一個獨立接口表示source class函數」更合適的話,就應該在inlining之前先使用Extract Interface。 - 修改所有source class引用點,改而引用absorbing class。 - 將source class聲明為private,以斬斷package之外的所有引用可能。 同時并修改source class的名稱,這便可使編譯器幫助你捕捉到所有對于source class的"dangling references "(虛懸引用點)。 - 編譯,測試。 - 運用Move Method 和 Move Field ,將source class的特性全部搬移至absorbing class。 - 為source class舉行一個簡單的喪禮。 **范例(Examples)** 先前(上個重構項〉我從TelephoneNumber「提煉出另一個class,現在我要將它inlining塞回到Person去。一開始這兩個classes是分離的: ~~~ class Person... public String getName() { return _name; } public String getTelephoneNumber(){ return _officeTelephone.getTelephoneNumber(); } TelephoneNumber getOfficeTelephone() { return _officeTelephone; } private String _name; private TelephoneNumber _officeTelephone = new TelephoneNumber(); class TelephoneNumber... public String getTelephoneNumber() { return ("(" + _areaCode + ") " + _number); } String getAreaCode() { return _areaCode; } void setAreaCode(String arg) { _areaCode = arg; } String getNumber() { return _number; } void setNumber(String arg) { _number = arg; } private String _number; private String _areaCode; ~~~ 首先我在Person中聲明TelephoneNumber「的所有「可見」(public)函數: ~~~ class Person... String getAreaCode() { return _officeTelephone.getAreaCode(); //譯注:請注意其變化 } void setAreaCode(String arg) { _officeTelephone.setAreaCode(arg); //譯注:請注意其變化 } String getNumber() { return _officeTelephone.getNumber(); //譯注:請注意其變化 } void setNumber(String arg) { _officeTelephone.setNumber(arg); //譯注:請注意其變化 } ~~~ 現在,我要找出TelephoneNumber的所有用戶,讓它們轉而使用Person接口。于是下列代碼: ~~~ Person martin = new Person(); martin.getOfficeTelephone().setAreaCode ("781"); ~~~ 就變成了: ~~~ Person martin = new Person(); martin.setAreaCode ("781"); ~~~ 現在,我可以持續使用Move Method 和 Move Field ,直到TelephoneNumber不復存在。
                  <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>

                              哎呀哎呀视频在线观看