Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize java facade mode

Shulou Source: shulou.com Published: 2022-06-01 04:51:22 10月25日 Update

This article mainly explains "how to realize the java facade model". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to realize the java facade model".

Take chestnut 1: the relevant departments that customers will encounter when they go to the local real estate bureau to apply for the transfer of property certificates.

For example, the design of chestnut 2:API gateway, if users want to access the subsystem, it is the access subsystem that is accessed indirectly through the API gateway.

Both of the above designs are facade mode.

Let's look at the UML class diagram in example 1.

Let's look at the code of the three subsystems:

1Universe / subsystem role

2class SubSystem01

3 {

4 public void method1 ()

5 {

6 System.out.println ("method1 () of subsystem 01 is called!")

7}

8}

1Universe / subsystem role

2class SubSystem02

3 {

4 public void method2 ()

5 {

6 System.out.println ("method2 () of subsystem 02 is called!")

7}

8}

1Universe / subsystem role

2class SubSystem03

3 {

4 public void method3 ()

5 {

6 System.out.println ("method3 () of subsystem 03 is called!")

7}

8}

two。 Let's look at the facade code.

1Universe / appearance character

2class Facade

3 {

4 private SubSystem01 obj1=new SubSystem01 ()

5 private SubSystem02 obj2=new SubSystem02 ()

6 private SubSystem03 obj3=new SubSystem03 ()

7 public void method ()

8 {

9 obj1.method1 ()

10 obj2.method2 ()

11 obj3.method3 ()

12}

13}

Application scenario of appearance pattern

You can usually consider using appearance mode in the following cases.

When building a hierarchical system, using the appearance pattern to define the entry point of each layer in the subsystem can simplify the dependency between the subsystems.

When there are many subsystems of a complex system, the appearance pattern can design a simple interface for the system for external access.

When there is a great relationship between the client and multiple subsystems, the introduction of appearance pattern can separate them, thus improving the independence and portability of the subsystem.

Thank you for your reading, the above is the content of "how to realize the java facade mode". After the study of this article, I believe you have a deeper understanding of how to realize the java facade model, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Subsystem pattern appearance facade role system learning design between code content customer situation real estate gateway chestnut complex very large three examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux Apple Huawei Microsoft