外观模式
隐藏了系统的复杂性,并向客户端提供了一个可以访问系统的接口。
子系统:
1 public interface Biz { 2 3 void doBiz(); 4 } 5 6 public class FirstBiz implements Biz { 7 8 @Override 9 public void doBiz() { 10 System.out.println("first biz"); 11 } 12 } 13 14 public class SecondBiz implements Biz { 15 16 @Override 17 public void doBiz() { 18 System.out.println("second biz"); 19 } 20 }
外观类:
1 public class BizFacade { 2 3 private FirstBiz firstBiz = new FirstBiz(); 4 5 private SecondBiz secondBiz = new SecondBiz(); 6 7 public void doFirstBiz() { 8 firstBiz.doBiz(); 9 } 10 11 public void doSecondBiz() { 12 secondBiz.doBiz(); 13 } 14 }
测试类:
1 public class Main { 2 3 public static void main(String[] args) { 4 BizFacade bizFacade = new BizFacade(); 5 bizFacade.doFirstBiz(); 6 bizFacade.doSecondBiz(); 7 } 8 }