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.