您的位置:首页 > 编程语言 > Java开发

九、外观模式facade

2017-03-29 16:43 134 查看

一、定义

为子系统中的一组接口提供一个一致的界面,次模式定义了一个高层接口,这个接口使得这个子系统更加容易使用。

二、结构图



三、代码示例

/**
* @use 测试外观模式 facade
* @author lattice
* @date 2016-12-26
*/
public class FacadeTest {

public static void main(String[] args) {
Facade facade=new Facade();
facade.methodA();
facade.methodB();

}

}
/**
* @use 定义外观类
* @author lattice
*
*/
class Facade{
SubSystemOne subOne;
SubSystemTwo subTwo;
SubSystemThree subThree;
SubSystemFour subFour;

public Facade(){
subOne=new SubSystemOne();
subTwo=new SubSystemTwo();
subThree=new SubSystemThree();
subFour=new SubSystemFour();
}
public void methodA(){
subOne.method1();
subTwo.method1();
}

public void methodB(){
subThree.method1();
subFour.method1();
}

}

/**
* @use 定义4个子系统类
* @author lattice
*
*/
class SubSystemOne{
public void method1(){
System.out.println("method one");
}
}
class SubSystemTwo{
public void method1(){
System.out.println("method two");
}
}
class SubSystemThree{
public void method1(){
System.out.println("method three");
}
}
class SubSystemFour{
public void method1(){
System.out.println("method fourx");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息