外观模式

  • 为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用
  • 应用
    • 在设计初期阶段,应该要有意识的将不同的两个层分离
    • 在开发阶段,子系统往往因为不断的重构演化而变得越来越复杂
    • 在维护一个遗留的大型系统时,可能这个系统已经非常难以维护和扩展
  • public class SubSystemOne {
        public void MethodOne(){
            System.out.println(" 子系统方法一");
        }
    }
    
    
    public class SubSystemTwo {
        public void MethodTwo(){
            System.out.println(" 子系统方法二");
        }
    }
    
    
    public class SubSystemThree {
        public void MethodThree(){
            System.out.println(" 子系统方法三");
        }
    }
    
    
    public class SubSystemFour {
    
        public void MethodFour(){
            System.out.println(" 子系统方法四");
        }
    }
    
    
    
    public class Facade {
        private SubSystemOne one;
        private SubSystemTwo two;
        private SubSystemThree three;
        private SubSystemFour four;
    
        public Facade() {
            one = new SubSystemOne();
            two = new SubSystemTwo();
            three = new SubSystemThree();
            four = new SubSystemFour();
        }
    
        public void MethodA() {
            System.out.println("
    方法组A()-----");
            one.MethodOne();
            two.MethodTwo();
            four.MethodFour();
        }
    
        public void MethodB() {
            System.out.println("
    方法组B()-----");
            two.MethodTwo();
            three.MethodThree();
        }
    
    }
    
    
    
    public class TestUtil {
    
        public static void main(String[] args) throws CloneNotSupportedException {
         
            Facade facade = new Facade();
            facade.MethodA();
            facade.MethodB();
    
        }
    }
原文地址:https://www.cnblogs.com/fatRabbit-/p/10201030.html