<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### 適配器模式(Adapter) 當我們手頭有某個類,而我們需要的卻是另外一個類,我們就可以通過 *適配器模式* 來解決問題。唯一需要做的就是產生出我們需要的那個類,有許多種方法可以完成這種適配。 ```java // patterns/adapt/Adapter.java // Variations on the Adapter pattern // {java patterns.adapt.Adapter} package patterns.adapt; class WhatIHave { public void g() {} public void h() {} } interface WhatIWant { void f(); } class ProxyAdapter implements WhatIWant { WhatIHave whatIHave; ProxyAdapter(WhatIHave wih) { whatIHave = wih; } @Override public void f() { // Implement behavior using // methods in WhatIHave: whatIHave.g(); whatIHave.h(); } } class WhatIUse { public void op(WhatIWant wiw) { wiw.f(); } } // Approach 2: build adapter use into op(): class WhatIUse2 extends WhatIUse { public void op(WhatIHave wih) { new ProxyAdapter(wih).f(); } } // Approach 3: build adapter into WhatIHave: class WhatIHave2 extends WhatIHave implements WhatIWant { @Override public void f() { g(); h(); } } // Approach 4: use an inner class: class WhatIHave3 extends WhatIHave { private class InnerAdapter implements WhatIWant { @Override public void f() { g(); h(); } } public WhatIWant whatIWant() { return new InnerAdapter(); } } public class Adapter { public static void main(String[] args) { WhatIUse whatIUse = new WhatIUse(); WhatIHave whatIHave = new WhatIHave(); WhatIWant adapt= new ProxyAdapter(whatIHave); whatIUse.op(adapt); // Approach 2: WhatIUse2 whatIUse2 = new WhatIUse2(); whatIUse2.op(whatIHave); // Approach 3: WhatIHave2 whatIHave2 = new WhatIHave2(); whatIUse.op(whatIHave2); // Approach 4: WhatIHave3 whatIHave3 = new WhatIHave3(); whatIUse.op(whatIHave3.whatIWant()); } } ``` 我想冒昧的借用一下術語“proxy”(代理),因為在 *《設計模式》* 里,他們堅持認為一個代理(proxy)必須擁有和它所代理的對象一模一樣的接口。但是,如果把這兩個詞一起使用,叫做“代理適配器(proxy adapter)”,似乎更合理一些。
                  <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>

                              哎呀哎呀视频在线观看