天天看點

外觀模式Facade

  外觀模式(Facade):為子系統中的一組接口提供一個一緻的界面,此模式定義了一個高層接口,

這個接口使得這一個子系統更加容易使用

  下面是類結構圖:

外觀模式Facade

   下面是源代碼:

    SubSystemOne.java

package com.china_chenglong;

public class SubSystemOne {

public void sayOne(){

System.out.println("say one");

}

}

    SubSystemTwo.java

package com.china_chenglong;

public class SubSystemTwo {

public void sayTwo(){

System.out.println("say two");

}

}

    SubSystemThree.java package com.china_chenglong; public class SubSystemThree { public void sayThree(){ System.out.println("say three"); } }     Facade.java package com.china_chenglong; public class Facade { private SubSystemOne one; private SubSystemTwo two; private SubSystemThree three; public Facade(){ one = new SubSystemOne(); two = new SubSystemTwo(); three = new SubSystemThree(); } public void Say(){ one.sayOne(); two.sayTwo(); three.sayThree(); } }     MainClass.java package com.china_chenglong; public class MainClass { public static void main(String[] args) { Facade facade = new Facade(); facade.Say(); } }