<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國際加速解決方案。 廣告
                ### 工廠方法模式 定義一個用于創建對象的接口,讓子類決定實例化哪一個類。工廠方法使一個類的實例化延遲到其子類。(摘抄) 工廠方法模式和簡單工廠模式都是用于去創建新的類,但是工廠方法模式傳承了簡單工廠模式封裝對象創建的過程,同時也改掉了簡單工廠模式違背開放——封閉原則的缺點。 簡單工廠模式,如果需要生產/去掉一個子類的話,那么需要在SimpleFactory類中修改 switch case 語句,所以違背了開放——封閉原則。 工廠方法創建對象是通過子工廠來創建,所以添加或刪除子類的話是不需要改變原有的代碼的。 ~~~ class Factory { public Product create() { // TODO Auto-generated method stub return null; } } class AFactory extends Factory { public Product create() { // TODO Auto-generated method stub return new AProduct(); } } class BFactory extends Factory { public Product create() { // TODO Auto-generated method stub return new BProduct(); } } class Product { public void domethod() { // TODO Auto-generated method stub } } class AProduct extends Product { public void domethod() { // TODO Auto-generated method stub } } class BProduct extends Product { public void domethod() { // TODO Auto-generated method stub } } //新增類 class CFactory extends Factory { public Product create() { return new CProduct(); } } class CProduct extends Product { public void domethod() { } } public static void main() { Factory factory = new AFactory(); Product product = factory.create(); product.domethod(); //新增一個類的話,那么只需要添加,而不需要修改原有代碼,因為生產類的判斷交給了客戶端 factory = new CFactory(); Product newP = factory.create(); newP.domethod(); } ~~~ 工廠方法模式差不多也就這樣,還是那句話實際使用中必須活學活用,多種模式結合出來的四不像模式,也許才是正確的使用方法。。。 話說《大話》的例子越來越扯了。。。感覺解釋還是蠻清楚,就是例子有點蛋疼,但是我也還蠻佩服作者,這樣子也可以圓過來。。。 好希望自己把這本書看完之后,可以去看下那本Gof寫的原版的設計模式,正好提升一下英文水平
                  <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>

                              哎呀哎呀视频在线观看