6.13. Appearance mode

发布时间 :2025-10-25 12:24:47 UTC      

Facade Pattern hides the complexity of the system and provides the client with an interface through which the client can access the system. This type of design pattern belongs to structural pattern, which adds an interface to the existing system to hide the complexity of the system.

This pattern involves a single class that provides simplified methods for client requests and delegate calls to existing system class methods.

6.13.1. Introduction

意图: Provides a consistent interface for a set of interfaces in the subsystem, and the appearance pattern defines a high-level interface that makes the subsystem easier to use.

主要解决: Reduce the complexity of accessing the internal subsystems of complex systems and simplify the interface between clients.

何时使用: 1. The client does not need to know the complex connections within the system, the whole system only needs to provide a “receptionist”. 2. Define the entrance of the system.

如何解决: The client is not coupled to the system, and the appearance class is coupled to the system.

关键代码: Add another layer between the client and the complex system, which deals with the order of calls, dependencies, and so on.

应用实例: 1. When you go to the hospital to see a doctor, you may have to register, outpatient, price, and take medicine, so as to make the patients or their families feel very complicated. If there is a receptionist, it is very convenient to let the receptionist handle it only. 2. The three-tier development mode of JAVA.

优点: 1. Reduce the interdependence of systems. 2. Improve flexibility. 3. The security is improved.

缺点: Do not comply with the principle of opening and closing, if it is troublesome to change things, it is not appropriate to inherit and rewrite.

使用场景: 1. A module that provides external access for complex modules or subsystems. 2. The subsystems are relatively independent. 3. Prevent the risks brought by low-level personnel.

注意事项: In a hierarchical structure, you can use appearance patterns to define entrances to each layer of the system.

6.13.2. Realize

We will create a Shape Interface and implementation of the Shape The entity class of the interface. The next step is to define an appearance class ShapeMaker .

ShapeMaker Classes use entity classes to represent user calls to these classes. FacadePatternDemo Class usage ShapeMaker Class to display the results.

外观模式的 UML 图

6.13.3. Step 1

Create an interface.

Shape.java

publicinterfaceShape{voiddraw();}

6.13.4. Step 2

Create an entity class that implements the interface.

Rectangle.java

publicclassRectangleimplementsShape{@Overridepublicvoiddraw(){System.out.println("Rectangle::draw()");}}

Square.java

publicclassSquareimplementsShape{@Overridepublicvoiddraw(){System.out.println("Square::draw()");}}

Circle.java

publicclassCircleimplementsShape{@Overridepublicvoiddraw(){System.out.println("Circle::draw()");}}

6.13.5. Step 3

Create an appearance class.

ShapeMaker.java

publicclassShapeMaker{privateShapecircle;privateShaperectangle;privateShapesquare;publicShapeMaker(){circle=newCircle();rectangle=newRectangle();square=newSquare();}publicvoiddrawCircle(){circle.draw();}publicvoiddrawRectangle(){rectangle.draw();}publicvoiddrawSquare(){square.draw();}}

6.13.6. Step 4

Use this appearance class to draw various types of shapes.

FacadePatternDemo.java

publicclassFacadePatternDemo{publicstaticvoidmain(String[]args){ShapeMakershapeMaker=newShapeMaker();shapeMaker.drawCircle();shapeMaker.drawRectangle();shapeMaker.drawSquare();}}

6.13.7. Step 5

Execute the program and output the result:

Circle::draw()
Rectangle::draw()
Square::draw()
Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.