外观模式

外观模式:为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这个子系统更加容易使用。以下是例子:

public class Facade {

ServiceA sa;

ServiceB sb;

public Facade(){

sa = new ServiceAImpl();

sb = new ServiceBImpl(); }

public void methodA(){

sa.methodA();

sb.methodB(); } }

 

//测试类

public class Test {  

public static void main(String[] args) {

//没有使用外观模式 

ServiceA sa = new ServiceAImpl();

ServiceB sb = new ServiceBImpl();

sa.methodA();

sb.methodB();

System.out.println("=========");

//使用了facade

Facade facade = new Facade();

facade.methodA(); } }

posted on 2012-05-19 15:55  lee0oo0  阅读(204)  评论(0)    收藏  举报