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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### 裝飾模式 動態地給一個對象添加一些額外地職責,就增加功能來說,裝飾模式比生成子類更為靈活(摘抄) 裝飾模式在添加功能方面確實非常靈活,當你需要給已經生成地類添加一個新的方法的時候,用裝飾模式真的是太方便了,你只需要知道自己需要給哪一個對象添加哪一個方法就ok了 裝飾模式一般用在增加原有類的核心職責或主要行為,在主類中加入了新的字段,新的方法和新的邏輯,從而增加了主類的復雜度。 ~~~ public interface SuperC { void Operation(); } public class Concrete implements SuperC { @Override public void Operation() { //被修飾的類的基本操作 } } public class Decorator implements SuperC { SuperC super1; public void setSuper (Super super1) { this.super1 = super1; } @Override public void Operation() { if (super1 != null) { super1.Operation(); } } } public class DecoratorA extends Decorator { @Override public void Operation() { super.Operation(); // 自己的操作 } } public class DecoratorB extends Decorator { @Override public void Operation() { super.Operation(); // 自己的操作 } public void SpecialB() { } } public class DecoratorC extends Decorator { @Override public void Operation() { super.Operation(); // 自己的操作 } public void SpecialC() { } } ~~~ 調用代碼: ~~~ public static void main (String args[]) { Concrete concrete = new Concrete(); DecoratorA a = new DecoratorA(); DecoratorB b = new DecoratorB(); DecoratorC c = new DecoratorC(); a.setSuper(concrete); //體現裝飾模式優勢的地方來了 b.setSuper(a); c.setSuper(a); } ~~~ 有沒有看出來有什么好處呢? 給類動態添加所需方法的優勢一下就體現了,當有需要兩個兩個對象分別有ab和ac兩種方法,這樣就可以很方便,而且當你需要添加更多的方法的時候,寫一個Decorator的子類,然后添加你需要裝飾的對象就可以了,繼承于Decorator類的功能類都是起到為Concrete類添加功能的作用 這樣做最大的好處就是有效的把類的核心職責和裝飾功能區分開了。而且可以去除相關類中重復的裝飾邏輯(摘抄)
                  <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>

                              哎呀哎呀视频在线观看