The appearance pattern is similar to a toolkit, and a class corresponds to a function.
The intent of the façade mode is to provide an interface for the subsystem to facilitate its use.
The example given in the book is to draw a dud flight path, the initial class design is like this, see,
There is a problem with the Showflight class: It mixes three features:
- Provide a panel for the flight path
- Display the flight path in the panel
- Calculate Flight path
The Showflight class works fine, but given that we will change some specific functionality later, we should refactor it into separate classes to improve maintainability and reusability, depending on the principle of separation of concerns.
We can make the following changes:
- Introduces a function class that defines the F () method, receives a double value (a time value), and returns a double value (the value of the function, that is, the coordinate value).
- Move the Createtitledpanel () method into the existing UI tool class to implement a panel that has a caption as the current Showflight class.
- Move the Showflight class into the Plotpanel class and use the function object instead to get the x and Y values. Defines the number of points required for a Plotpanel constructor to receive two function instances and drawings.
Class diagram Design,
The Main method is still written in Showflight, but we name it ShowFlight2. The function class is used to obtain the corresponding x and Y coordinate values. However, because the specific x and Y are a value, then the specific problem is determined. Plotpanel uses the function implementation method to obtain the X and Y values to paint. The UI class is then given a plotpanel reference to a well-drawn graph to create a jpanel with a border. Finally ShowFlight2 generates a frame and uses the UI class method to get the complete trajectory graph interface (using the singleton design pattern, the ShowFlight2 class first gets the UI singleton, and then calls the method).
The original Showflight class is an example program, it can run directly, but the function of the subsystem is not reusable, and after the reconstructed appearance class is a configurable, reusable class, provides a high-level interface, making the use of subsystems more convenient.
Java Design pattern (designer PATTERNS in JAVA) reading abstract 1th Interface Mode--4th Chapter appearance (facade) mode