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