zoukankan      html  css  js  c++  java
  • 外观模式

    外观模式(Facade Pattern)隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口。这种类型的设计模式属于结构型模式,它向现有的系统添加一个接口,来隐藏系统的复杂性。

    Hospital类

     1 package top.bigking.facade;
     2 
     3 /**
     4  * @Author ABKing
     5  * @since 2020/2/22 下午2:40
     6  **/
     7 public class School {
     8     public School() {
     9         System.out.println("学校");
    10     }
    11 }

    School类

     1 package top.bigking.facade;
     2 
     3 /**
     4  * @Author ABKing
     5  * @since 2020/2/22 下午2:40
     6  **/
     7 public class School {
     8     public School() {
     9         System.out.println("学校");
    10     }
    11 }

    Bank类

     1 package top.bigking.facade;
     2 
     3 /**
     4  * @Author ABKing
     5  * @since 2020/2/22 下午2:44
     6  **/
     7 public class Bank {
     8     public Bank() {
     9         System.out.println("银行");
    10     }
    11 }

    门面类:

     1 package top.bigking.facade;
     2 
     3 /**
     4  * @Author ABKing
     5  * @since 2020/2/22 下午2:44
     6  **/
     7 public class RegisterFacade {
     8     public static void register(){
     9         Bank bank = new Bank();
    10         Hospital hospital = new Hospital();
    11         School school = new School();
    12     }
    13 }

    单元测试:

     1 package top.bigking.facade;
     2 
     3 import org.junit.Test;
     4 
     5 /**
     6  * @Author ABKing
     7  * @since 2020/2/22 下午2:46
     8  **/
     9 public class TestFacade {
    10     @Test
    11     public void testFacade(){
    12         RegisterFacade.register();
    13     }
    14 }

    开发常用的场景:

    频率很高,哪里都会遇到。各种技术和框架中,都有外观模式的使用。如:

    JDBC封装后的,commons提供的DBUtils类,Hibernate提供的工具类、Spring JDBC工具类。

    金麟岂是池中物,一遇风云便化龙!
  • 相关阅读:
    H5 后代选择器
    H5 id选择器和class选择器
    H5 类选择器
    H5 id选择器
    H5 标签选择器
    H5 颜色属性
    H5 文本属性
    H5 文字属性的缩写
    H5 字体属性补充
    H5 文字属性
  • 原文地址:https://www.cnblogs.com/ABKing/p/12345426.html
Copyright © 2011-2022 走看看