设计模式之外观模式

Java31

本文通过老王对小王公司整体结构的改造,解释了小王公司的面貌模式。所谓的外观模式实际上是从各种复杂的子系统中抽象出一个接口,以隐藏特定的实现细节。当调用方调用时,您只需要调用接口。为了加深我们的理解,我们将重点介绍外观模式在源代码中的应用。最后,我对设计模式的学习过程进行了一些思考。

[En]

This paper explains the appearance pattern through Lao Wang's transformation of the overall structure of Xiao Wang Company. the so-called appearance pattern is actually abstracting an interface from a variety of complex subsystems to hide the specific implementation details. when the caller calls, you only need to call the interface. In order to deepen our understanding, we will focus on the application of appearance patterns in the source code. finally, I have some thoughts on the learning process of design patterns.

读者可以拉取完整代码到本地进行学习,实现代码均测试通过后上传到码云

一、引出问题

随着小王创业的深入,公司的业务模块也越来越复杂。每当客户与他合作时,都要深入到每个模块,客户还要依赖小王的每个模块,这给使用该模块的客户带来了困难。

[En]

With the deepening of Xiao Wang's entrepreneurship, the business modules of the company are becoming more and more complex. Whenever customers cooperate with him, they have to go deep into each module, and customers have to rely on each module of Xiao Wang, which brings difficulties to customers who use the module.

小王就想请老王帮他规划一下公司的架构。

老王听完了小王的需求,开始给他分析问题。

现在公司的结构已经演变得相当复杂,客户通过各个子系统访问你,你应该把你所有的子系统集成到前天(界面)。客户只需要通过这个前台(界面)访问您的子系统。这可以很好地解决这个问题。

[En]

Now the structure of the company has evolved quite complex, customers visit you through various subsystems, you should integrate all your subsystems into a day before yesterday (interface). Customers only need to access your subsystem through this foreground (interface). This can solve the problem very well.

二、概念与运用

老王提出的解决方案是外观模式,通过提供一致的界面,让它更容易被多个复杂的子系统访问。

[En]

The solution proposed by Lao Wang is the appearance pattern, which makes it more accessible to multiple complex subsystems by providing a consistent interface.

该模式具有统一的接口,外部应用不需要关注内部子系统的具体细节,将大大降低应用的复杂性,提高程序的可维护性。

[En]

The mode has a unified interface, and the external application does not need to pay attention to the specific details of the internal subsystem, which will greatly reduce the complexity of the application and improve the maintainability of the program.

输入验证码查看隐藏内容

扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长

相关文章
Java

设计模式之观察者模式

观察者模式是极其重要的一个设计模式,也是我几年开发过程中使用最多的设计模式,本文首先概述观察者模式的基本概念和Demo实现,接着是观察者模式在Java和Spring中的应用,最后是对观察者模式的应用场...
Java

Fizz网关入门教程-安装

概述 Fizz网关是一个基于 Java开发的微服务聚合网关,能够实现热服务编排聚合、自动授权选择、线上服务脚本编码、在线测试、高性能路由、API审核管理、回调管理等目的,拥有强大的自定义插件系统可以自...
Java

复杂逻辑题目的好帮手:注释和断言

前言 最近在刷题的时候,遇到一些逻辑比较复杂的题,往往会遇到困难,经常写不出来。即使在有debug帮助的时候,也往往会出现思虑不周,导致一错再错的情况,即好不容易debug通过一个测试用例,然后发现被...
Java

动物期末代码

``` Animal.java public abstract class Animal { public abstract void cry(); public abstract String ge...
Java

集合

1、Abstract开头的类用于设置自己的类库,其中已有部分实现,比直接实现接口方便得多。 2、迭代器在调用next()方法之前必须先调用hasNext()方法,否则将抛出 NoSuchElement...
Java

DHCP 动态主机设置协议 分析

在TCP/IP网络中,每个接口都需要一个IP地址、子网掩码和广播地址( IPv6中没有),简单来说就是需要网络配置信息。如果想访问外部网络可以通过DNS获取外部地址,再通过路由间接转发出去。但是在"家...
Java

Swagger框架

开发软件:IDEA 项目类型:SpringBoot的JavaWeb 官网:https://swagger.io/ 在线文档:https://swagger.io/docs/specification/...
Java

B树索引的相关概念

B树索引的相关概念 索引与表一样,也属于段(segment)的一种。里面存放了用户的数据,跟表一样需要占用磁盘空间。只 但是,索引中的数据存储形式与表中的数据格式非常不同。在理解索引时,您可以想象一本...
Java

MySQL的三值逻辑

MySQL 采用三值逻辑 SELECT 1 = 1; SELECT 1 = 2; SELECT 1 = NULL; SELECT 1 != NULL; 上面四条语句的结果分别为: 可见MySQL采用三...
Java

CMS前世今生

CMS一直是面试中的常考点,今天我们用通俗易懂的语言简单介绍下。 垃圾回收器为什么要分区分代? 如上图:JVM虚拟机将堆内存区域分代了,先生代是朝生夕死的区域,老年代是老不死的区域,不同的年代对象有不...
Java

深拷贝和浅拷贝

java代码实现 浅拷贝:你获取 teacher1拷贝后的对象 teacher2,你使用 teacher2去修改某个引用对象会改变之前的对象的引用,相当于将 teacher2的引用指向 teacher...
Java

Liunx-CentOS安装Nginx

# 查看nginx是否运行 ps -ef | grep nginx # 停止用stop、或者用kill /usr/local/nginx/sbin/nginx -s stop # 查询Nginx安装的...