Facade of Java design pattern

summary

External and internal subsystems must communicate through a unified appearance mode object, that is, appearance mode, also known as facade mode. Generally speaking, the facade pattern is to reduce the dependency between the client and the implementation layer. The purpose of appearance mode is to provide a centralized and simplified communication channel for subsystems.

UML class diagram

In the above UML diagram, three roles appear:

Client role: the user can call the class of appearance mode through the client to operate the subsystem; facade: the client can call this class, which includes calling specific functions in the subsystem; subsystem role (module): defines specific individual functions in the subsystem;

Code example:

In the above code, the facade class acts as the appearance interface of ModuleA, moduleb and modulec modules. Through this class, the client does not need to call the ABC module of the subsystem in person or know the internal details of the system, so as to better realize the decoupling between the client and the system.

At the same time, the appearance mode can also be used to selectively expose methods. The methods defined in a module can be divided into two parts, one for external use of the subsystem and the other for mutual calls between modules within the subsystem.

Advantages of appearance mode

The appearance mode looses the coupling relationship between the client and the subsystem, making it easier for the modules inside the subsystem to expand and maintain.

Make the subsystem easier to use. The client no longer needs to understand the implementation inside the subsystem, nor does it need to interact with many modules inside the subsystem. It only needs to interact with appearance classes.

It can help us better divide the level of access. Some methods are used outside the system, while others are used inside the system. The functions that need to be exposed to the outside are concentrated in the facade, which is not only convenient for the client to use, but also hides the internal details.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>