zoukankan      html  css  js  c++  java
  • 设计模式(Facade)状态(注意事项)

    外观模式(Facade),子系统的一组接口提供一个一致的界面,该模式定义了一个高层次接口,这个接口使得这一子系统更加easy采用。
    外观模式完美地体现了依赖反转原则,迪米特法则的想法,式之中的一个。


    外观模式结构图例如以下:
    这里写图片描写叙述

    定义三个子系统类

    public class SubSystemOne {
    
        public void methodOne(){
            System.out.println("子系统方法1");
        }
    }
    
    public class SubSystemTwo {
    
        public void methodTwo(){
            System.out.println("子系统方法2");
        }
    }
    
    public class SubSystemThree {
    
        public void methodThree(){
            System.out.println("子系统方法3");
        }
    }

    定义一个外观Facade类

    public class Facade {
    
        private SubSystemOne one;
        private SubSystemTwo two;
        private SubSystemThree three;
    
        public Facade(){
            one =new SubSystemOne();
            two=new SubSystemTwo();
            three=new SubSystemThree();
        }
    
        public void methodA(){
            one.methodOne();
            three.methodThree();
        }
    
        public void methodB(){
            one.methodOne();
            two.methodTwo();
        }
    }

    client代码

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

    因为Facade类的作用。client能够根本不知道三个子系统的存在

    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    php字符串相加
    elementUI的input输入一个字符就失去焦点问题
    js鸡尾酒排序算法
    js快速排序算法
    js冒泡排序算法改进
    js实现队列
    EXIF.js 读取图片的方向
    new Image().src资源重复请求问题
    canvas绘制圆图输出图片格式
    去掉"You are running Vue in development mode"提示
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4876366.html
Copyright © 2011-2022 走看看