Java Design pattern (designer PATTERNS in JAVA) reading abstract 1th Interface Mode--4th Chapter appearance (facade) mode

Source: Internet
Author: User

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:

    1. Provide a panel for the flight path
    2. Display the flight path in the panel
    3. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.