测试类:
1 public class Test { 2 3 public static void main(String[] args) { 4 ServiceA sa = new ServiceAImpl(); 5 ServiceB sb = new ServiceBImpl(); 6 7 sa.methodA(); 8 sb.methodB(); 9 10 System.out.println("========"); 11 //facade 12 Facade facade = new Facade(); 13 facade.methodA(); 14 facade.methodB(); 15 } 16 } 1 public interface ServiceA { 2 public void methodA(); 3 } 1 public class ServiceAImpl implements ServiceA { 2 3 public void methodA() { 4 System.out.println("这是服务A"); 5 } 6 } 1 public interface ServiceB { 2 public void methodB(); 3 } 1 public class ServiceBImpl implements ServiceB { 2 3 public void methodB() { 4 System.out.println("这是服务B"); 5 } 6 } 1 public interface ServiceC { 2 public void methodC(); 3 } 1 public class ServiceCImpl implements ServiceC { 2 3 public void methodC() { 4 System.out.println("这是服务C"); 5 } 6 } 1 public class Facade { 2 3 ServiceA sa; 4 5 ServiceB sb; 6 7 ServiceC sc; 8 9 public Facade() { 10 sa = new ServiceAImpl(); 11 sb = new ServiceBImpl(); 12 sc = new ServiceCImpl(); 13 } 14 15 public void methodA() { 16 sa.methodA(); 17 sb.methodB(); 18 } 19 20 public void methodB() { 21 sb.methodB(); 22 sc.methodC(); 23 } 24 25 public void methodC() { 26 sc.methodC(); 27 sa.methodA(); 28 } 29 }
转载于:https://www.cnblogs.com/huzi007/p/4045337.html