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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 設計模式 ### 單例模式 ~~~JAVA package com.dodoke.demo5; /** * 單例模式-餓漢式單例模式 * @author 一教室 * */ public class ClientE { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } private int age; public int getAge() { return age; } public void setAge(int age) { this.age = age; } /** * 因為構造器私有,所以這能在本類中調用構造器 * 單例類必須自己創建自己的唯一實例。 */ private static ClientE clientE = new ClientE(); /** * 單例類必須給所有其他對象提供這一實例。 * 寫一個方法對外提供clientE */ public static ClientE getInstance() { return clientE; } /** * 構造器本質上也是一種方法,只不過是一種特殊的方法,沒有返回值,只能用來創建對象 */ private ClientE() { } } ~~~ ~~~java package com.dodoke.demo5; /** * 單例模式-飽漢式單例模式(懶漢式單例模式) * @author 一教室 * */ public class ClientB { /** * 此時沒有主動開辟內存空間 */ private static ClientB clientB;//null /** * 相較于餓漢式單例模式,飽漢式單例模式不會主動去開辟內存空間創建對象,只有在調用對外方法getInstance的時候才會創建對象 * 節省了系統開銷 * @return */ public static ClientB getInstance() { if(null == clientB) { clientB = new ClientB();//在調用對外方法的時候為clientB開辟內存空間 } return clientB; } private ClientB() { } } ~~~ ~~~java package com.dodoke.demo5; public class Demo { public static void main(String[] args) { /** * 打印出來后,c1和c2指向的是同一個地址 * 它們僅僅只是變量名不同,本質上是同一個對象 */ ClientE c1 = ClientE.getInstance(); c1.setName("陸文鑫"); System.out.println(c1); ClientE c2 = ClientE.getInstance(); System.out.println(c2); System.out.println(c2.getName()); c2.setAge(27); System.out.println(c1.getAge()); ClientB c3 = ClientB.getInstance(); ClientB c4 = ClientB.getInstance(); System.out.println(c3); System.out.println(c4); } } ~~~ ### 工廠模式 ~~~java package com.dodoke.demo5; public interface Product { /** * 產品說明書 */ public void desc(); } ~~~ ~~~java package com.dodoke.demo5; public class MobliePhone implements Product { @Override public void desc() { System.out.println("生產手機"); } } ~~~ ~~~java package com.dodoke.demo5; public class Pad implements Product { @Override public void desc() { System.out.println("生產平板"); } } ~~~ ~~~java package com.dodoke.demo5; public class Computer implements Product { @Override public void desc() { System.out.println("生產電腦"); } } ~~~ ~~~java package com.dodoke.demo5; /** * 簡單工廠模式 * @author 一教室 * 好比簡單工廠就是一個小作坊,客戶來訂單我才開始生產對應產品 */ public class SimpleFactory { /** * 生產方法 * @param order 相當于客戶的訂單信息 * @return */ public static Product produce(String order) { if("phone".equals(order)) { return new MobliePhone();//根據對應訂單信息生產對應產品 } else if("computer".equals(order)) { return new Computer(); } else if("pad".equals(order)) { return new Pad(); } else { return null; } } } ~~~ ~~~java package com.dodoke.demo5; /** * 工廠模式 * @author 一教室 * 相當于工廠做大做強,不再是之前小作坊,有了自己的生產線 */ public class Factory { //手機生產線 public static Product producePhone() { return new MobliePhone(); } //電腦生產線 public static Product produceComputer() { return new Computer(); } //平板生產線 public static Product producePad() { return new Pad(); } } ~~~ ~~~java package com.dodoke.demo5; public class Demo2 { public static void main(String[] args) { Product pdt = SimpleFactory.produce("computer"); pdt.desc(); Product pdt2 = Factory.producePhone(); pdt2.desc(); } } ~~~
                  <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>

                              哎呀哎呀视频在线观看