面板模式之java實現

來源:互聯網
上載者:User

標籤:oid   tee   而不是   one   使用   pre   分享   png   ima   

站在使用者角度:使用者做一件事,本來需要去瞭解做這些事的具體流程(並且這些事的流程的各個子流程是可以進行組合使用的),但是現在使用者希望一個對象能夠把這些流程集中在一起,使用者調用這個對象的方法就可以實現這個流程而不是讓使用者知道這個流程是什麼樣子的。

 

站在實現者角度:滿足使用者需求,暴露一些方法(每個方法都是一些子流程的組合),此時實現者需要知道每個子流程相關的對象。

 

package com.facade;/** * 為了滿足使用者需求 需要有一個外觀對象知道所有實現這些子流程的對象 * 並且外觀對象需要調用它們 使用者有事就找外觀 * @author 黃二狗 * */public class Facade {        private SubSystemOne subSystemOne;    private SubSystemTwo subSystemTwo;    private SubSystemThree subSystemThree;            //外觀需要知道所有實現子流程的對象    public Facade()    {        subSystemOne=new SubSystemOne();        subSystemTwo=new SubSystemTwo();        subSystemThree=new SubSystemThree();    }        public void methodA()    {        //具體子流程的排列組合        subSystemOne.MethodOne();        subSystemOne.MethodOne2();        subSystemThree.MethodThree();    }        public void methodB()    {        subSystemOne.MethodOne2();        subSystemOne.MethodOne();        subSystemThree.MethodThree();        subSystemTwo.MethodTwo();    }}
package com.facade;/** * 子流程對象A  這些子流程一般不是同一條繼承鏈上的對象 * @author 黃二狗 * */public class SubSystemOne {       public void MethodOne()   {       System.out.println("子流程對象One的第一個方法");   }      public void MethodOne2()   {       System.out.println("子流程對象One的第二個方法");   }}
package com.facade;public class SubSystemTwo {        public void MethodTwo()       {           System.out.println("子流程對象Two的第一個方法");       }}
package com.facade;public class SubSystemThree {    public void MethodThree()       {           System.out.println("子流程對象Thtee的第一個方法");       }}
package com.facade;public class Client {   public static void main(String[] args) {    Facade facade=new Facade();    //第一套流程    facade.methodA();    System.out.println("==================分割線=============================");    //第二套流程    facade.methodB();  }}

 

面板模式之java實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.