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工具类。

    金麟岂是池中物,一遇风云便化龙!
  • 相关阅读:
    学习:组件生命周期(2)
    学习:组件生命周期(3)
    学习:深入分析布局文件(HelloWorld)
    wap webapp app区别
    TCP的数据传输
    SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 详解
    未能加载文件或程序集“SqlServerDal”或它的某一个依赖项。系统找不到指定的文件。
    人生的十个不要等
    asp.net网站三层架构详解和反射知识
    工厂模式概况
  • 原文地址:https://www.cnblogs.com/ABKing/p/12345426.html
Copyright © 2011-2022 走看看