Using design Patterns in Java to optimize the development of command-line interaction programs

Source: Internet
Author: User
Keywords Java design patterns interactive programs optimizing command lines
Tags aliyun change command line computer design design patterns development example

The mode of human-computer interaction originated from the command line interaction, although the interactive mode of graphical interface is more and more widely used, but command line interaction still has its irreplaceable position. command-line interaction is a command-line approach to http://www.aliyun.com/zixun/aggregation/11432.html "> Human interaction, that is, users follow the prompts of the program, step-by-step input, and the program is responsible for interpretation and final execution of instructions.

This article takes a simple example of deploying a war package to illustrate the problems encountered in command-line interaction programming and how to use design patterns to solve these problems.

Introduction to Examples

In the instance, the command-line interaction gives a set of questions requesting user input and then deploys the war package to the server based on user input. As shown in Figure 1, the application has a total of 7 problems, requiring users to enter different deployment information. These issues will interact with the user in a particular order, and the user then gives the answer to the problem.

Figure 1. Single War Package Deployment instance

Question 1. Traditional command-line interaction mode does not support fallback and jump

As shown in Figure 1, there are 7 problem requests to deploy the war package to the server. Instead of answering 7 questions in turn, users need to answer questions 1, 2, 3, 6, 7 when the war package exists, and the user needs to answer 1, 2, 4, 5, 6, 7 when the war package does not exist. Therefore, depending on the user input, you may encounter a different flow of problems. In the traditional command-line interaction mode, the user can only follow the order of the problem flow, can not be rolled back and jump, for example, the user moved to question 3 o'clock, can not be back to issue 2.

Question 2. Traditional command-line interaction patterns are difficult to adapt to changing requirements

When the requirements of the program change, the traditional command line interaction mode is difficult to adapt to change. In Figure 1, for example, when more than one war package needs to be deployed, the flowchart becomes shown in Figure 2, and the traditional program lacks flexibility in dealing with this change.

Figure 2. Multiple War Package deployment instances

This section uses design patterns to give the design of Figure 1, a single war package deployment, and then expands on the design of Figure 1 to achieve the requirements of Figure 2 (multiple War package deployments).

Appellation conventions

In order to describe conveniently, this paper describes a problem of the program and a user's input combination as a problem. The order of the program prompts the problem is called the problem flow. The ability for a user to enter a specific character at any problem to return the previous question is called a fallback, and the function of a user entering a specific character and problem number to display a question has been called a jump.

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.