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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## **一、單例模式** 特點: * 單例類只能有一個實例 * 單例類必須自己創建自己的唯一實例 * 單例類必須給所有其他對象提供一個全局的實例 ## 單例模式之懶漢模式 ``` /** * 文件描述: * 創建用戶:emotion * 創建時間:2019/12/9 */ public class SingletonPattern { /** * 內存可見性,所有線程都能看到共享內存的最新狀態 */ private static volatile SingletonPattern singletonPattern; /** * 保護行構造方法,不允許被實例化 */ private SingletonPattern(){} /** * 獲取唯一實例 * 雙重檢查鎖定 */ public static SingletonPattern getInstance(){ //先檢查實例是否存在,如果不存在才進入下面的同步塊 if(singletonPattern==null){ //同步塊,線程安全的創建實例 synchronized (SingletonPattern.class){ //再次檢查實例是否存在,如果不存在才真正的創建實例 if(singletonPattern==null){ singletonPattern = new SingletonPattern(); } } } return singletonPattern; } } ``` ## 單例模式之餓漢模式 ``` /** * 文件描述: * 創建用戶:emotion * 創建時間:2019/12/9 */ public class SingletonPattern { //類加載的時候就創建實例 private static SingletonPattern singletonPattern = new SingletonPattern(); /** * 保護行構造方法,不允許被實例化 */ private SingletonPattern(){} /** * 獲取唯一實例 */ public static SingletonPattern getInstance(){ return singletonPattern; } } ``` ## **工廠模式** * 常用的工廠模式是靜態工廠,利用static方法, * 作為一種類似于常見的工具Utils等輔助效果 * 一般情況下工廠類不需要被實例化 ``` interface food{} class A implements food{} class B implements food{} class C implements food{} public class FactoryPattern { /** * 保護型構造,不允許被實例化 */ private FactoryPattern(){} public static food getA(){ return new A(); } public static food getB(){ return new B(); } public static food getC(){ return new C(); } } class Client{ //客戶端代碼只需要將相應的參數傳入即可得到對象 //用戶不需要了解工廠類內部的邏輯。 public void get(String name){ food x = null ; if ( name.equals("A")) { x = FactoryPattern.getA(); }else if ( name.equals("B")){ x = FactoryPattern.getB(); }else { x = FactoryPattern.getC(); } } } ``` ## **抽象工廠模式**
                  <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>

                              哎呀哎呀视频在线观看