Blog: bugstack.cn

Precipitation, share, grow, let yourself and others can gain something! 😄

One, foreword

Boss you add money my code can fly

There are two kinds of programmers; Those who love and those who just work. Those who like code programming will take the initiative to learn to enrich their wings, and they also like to explore technology and try to apply the knowledge they have learned to the development of business requirements at ordinary times. For this part of the small partners working to write code can make money is really happy!

How do you become the coding guy

You enjoy whatever you do and often derive a sense of accomplishment from continuing to do it. In terms of programming, because one line of code affected millions of people, because one line of code made the system more stable, because one line of code survived all the seconds, and so on, lines of code are lessons learned over time. If you want to be a programmer like this, you need to keep learning and keep applying your code to more core systems with more skills and knowledge.

Efforts in the wrong direction are in vain

You put in a lot of time, but you don’t get much in return. For example, sometimes many friends ask me how I can learn a content THAT I have never touched before. My personal experience is very recommended, do not learn too much theoretical content at first, but try to practice, to learn the content to do some Demo cases. It’s kind of like when you buy a bike do you take it apart and learn how it works, or do you ride it a few times? Even if you fall on your face, it’s an experience you have to go through.

At the same time, I also know that many people have not gained much from the design mode, which is mainly caused by the lack of cases or cases not close to the actual scene and lack of learning direction. Space, too empty, too mysterious, let a person have no grip!

Therefore, I began to write articles about design patterns based on actual cases to help everyone grow up and also let myself precipitation!

Second, development environment

  1. JDK 1.8
  2. Idea + Maven
  3. Involving engineering three, can be concerned byThe public,:Bugstack wormhole stackReply,Download the source codeGet (Open the get link and find the serial number 18)
engineering describe
itstack-demo-design-4-00 Scene simulation engineering, simulation of online examination question bank extraction out of order
itstack-demo-design-4-01 Using a lump of code to implement business requirements is also the use of ifelse
itstack-demo-design-4-02 Design patterns are optimized to adapt code to generate contrast for learning

Iii. Introduction of prototype mode

The prototype mode mainly solves the problem of creating duplicate objects, which are complicated and may take a long time to obtain data from libraries or RPC interfaces. Therefore, cloning is adopted to save time.

In fact, this scenario happens all the time, but it is rarely used in our own development, like;

  1. Do you oftenCtrl+C,Ctrl+V, copy and paste the code.
  2. API methods provided in most Java classes;Object clone().
  3. Mitosis of cells.

There are a lot of scenarios like this, but if you think about your daily code development, is this a useful design pattern? It’s not so easy to find, and sometimes even ignore the way this design pattern works. Think about which scenarios you can use before reading the rest of the article.

4. Case scenario simulation

Everyone has taken exams, from papermaking to computer-based answering, and there are hundreds of tests, big and small. And before sitting in the classroom to answer the people around are a set of papers, the exam time can also steal or others to send information to copy a copy of the answer.

But from part of the content can be on the computer to test the beginning, in order to ensure the fairness of the same topic, began to appear test questions mixed more do good answer options also mixed. This greatly increased the cost of copying, but also better to achieve the fairness of the test.

But what would you do if the need for fairness were assigned to you?

Because of the need to achieve a computer test extraction service, so here to build a database topic scene class information, used to create; Multiple choice questions, essay questions.

1. Scene simulation engineering

itstack-demo-design-4-00└ ─ ─ the SRC └ ─ ─ the main └ ─ ─ Java └ ─ ─ org. Itstack. The demo, the design ├ ─ ─ AnswerQuestion. Java └ ─ ─ ChoiceQuestion. JavaCopy the code
  • Here we simulate the class of two test paper questions;ChoiceQuestion(Multiple choice),AnswerQuestion(Essay question). If it is the actual business scenario development, there will be more question types, you can recall your college entrance examination paper.

2. Scenario description

2.1 choice

public class ChoiceQuestion {

    private String name;                 / / the topic
    private Map<String, String> option;  / / options; A, B, C, D
    private String key;                  / / the answer; B

    public ChoiceQuestion(a) {}public ChoiceQuestion(String name, Map<String, String> option, String key) {
        this.name = name;
        this.option = option;
        this.key = key;
    }

    / /... get/set
}
Copy the code

2.2 question

public class AnswerQuestion {

    private String name;  / / the problem
    private String key;   / / the answer

    public AnswerQuestion(a) {}public AnswerQuestion(String name, String key) {
        this.name = name;
        this.key = key;
    }

    / /... get/set
}
Copy the code
  • The above two classes are the material content needed in our scene, which is relatively simple. If you want to expand your learning while testing, you can continue to add other materials (Topic type).

Five, with a lump of code implementation

There is no ifelse in today's implementation, but there is no business that a class cannot solve, if you are bold!

In the following example we will create test questions for each user and return them to the caller.

1. Engineering structure

itstack-demo-design-4-01└ ─ ─ the SRC └ ─ ─ the main └ ─ ─ Java └ ─ ─ org. Itstack. Demo. The design └ ─ ─ QuestionBankController. JavaCopy the code
  • A class of several thousand lines of code have you ever seen ho? That today let you see again have such potential class!

2. A shuttle to fulfill requirements

public class QuestionBankController {

    public String createPaper(String candidate, String number) {

        List<ChoiceQuestion> choiceQuestionList = new ArrayList<ChoiceQuestion>();
        List<AnswerQuestion> answerQuestionList = new ArrayList<AnswerQuestion>();

        Map<String, String> map01 = new HashMap<String, String>();
        map01.put("A"."JAVA2 EE");
        map01.put("B"."JAVA2 Card");
        map01.put("C"."JAVA2 ME");
        map01.put("D"."JAVA2 HE");
        map01.put("E"."JAVA2 SE");

        Map<String, String> map02 = new HashMap<String, String>();
        map02.put("A"."The Main method of a JAVA program must be inside a class.");
        map02.put("B"."JAVA programs can have multiple main methods.");
        map02.put("C"."Class names must be the same as file names in JAVA programs.");
        map02.put("D"."If there is only one statement in the main method of a JAVA program, it can be enclosed without {}(curly braces).");

        Map<String, String> map03 = new HashMap<String, String>();
        map03.put("A"."Variables are randomly composed of letters, underscores, digits, and $signs;");
        map03.put("B"."Variables cannot start with a number;");
        map03.put("C"."A and A are the same variable in Java;");
        map03.put("D"."Different types of variables can have the same name;");

        Map<String, String> map04 = new HashMap<String, String>();
        map04.put("A"."STRING");
        map04.put("B"."x3x;");
        map04.put("C"."void");
        map04.put("D"."de$f");

        Map<String, String> map05 = new HashMap<String, String>();
        map05.put("A"."31");
        map05.put("B"."0");
        map05.put("C"."1");
        map05.put("D"."2");

        choiceQuestionList.add(new ChoiceQuestion("Not included in the version defined by JAVA", map01, "D"));
        choiceQuestionList.add(new ChoiceQuestion("What is true of the following statement?", map02, "A"));
        choiceQuestionList.add(new ChoiceQuestion("What is true about variable naming conventions?", map03, "B"));
        choiceQuestionList.add(new ChoiceQuestion("The following () is not a valid identifier", map04, "C"));
        choiceQuestionList.add(new ChoiceQuestion("The expression 11 plus 3 times 8 over 4% is equal to 3.", map05, "D"));
        answerQuestionList.add(new AnswerQuestion("How many legs did a little red horse and a little black horse have?"."Four legs"));
        answerQuestionList.add(new AnswerQuestion("Iron or wood?"."The worst headache"));
        answerQuestionList.add(new AnswerQuestion("What bed you can't sleep in?"."Jaws"));
        answerQuestionList.add(new AnswerQuestion("Why doesn't a good horse turn its back?"."The grass is gone in the back."));

        // Output the result
        StringBuilder detail = new StringBuilder("Candidate:" + candidate + "\r\n" +
                "Test Number:" + number + "\r\n" +
                "--------------------------------------------\r\n" +
                1. Multiple choice questions + "\r\n\n");

        for (int idx = 0; idx < choiceQuestionList.size(); idx++) {
            detail.append("The first").append(idx + 1).append("Question:").append(choiceQuestionList.get(idx).getName()).append("\r\n");
            Map<String, String> option = choiceQuestionList.get(idx).getOption();
            for (String key : option.keySet()) {
                detail.append(key).append(":").append(option.get(key)).append("\r\n");
                ;
            }
            detail.append("Answer:").append(choiceQuestionList.get(idx).getKey()).append("\r\n\n");
        }

        detail.append(2. Essay Questions + "\r\n\n");

        for (int idx = 0; idx < answerQuestionList.size(); idx++) {
            detail.append("The first").append(idx + 1).append("Question:").append(answerQuestionList.get(idx).getName()).append("\r\n");
            detail.append("Answer:").append(answerQuestionList.get(idx).getKey()).append("\r\n\n");
        }

        returndetail.toString(); }}Copy the code
  • Such code tends to be very easy to understand, given whatever program you want, not object-oriented, just procedural. Don’t worry about scalability, just work.
  • The above code mainly consists of three parts; First, create multiple choice and essay questions into the collection, define the detail string to wrap the results, and return the result content.
  • But the above code has not implemented a place is not out of order, everyone’s paper order is the same. If you want to add out of order, you can do that, but the complexity increases.This is not to show too much concrete implementation, only after the comparison of reconstruction.

3. Test and verify

Next, we verify the interface services through junit unit tests, emphasizing that routine single-test writing can better improve the robustness of the system.

Writing test classes:

@Test
public void test_QuestionBankController(a) {
    QuestionBankController questionBankController = new QuestionBankController();
    System.out.println(questionBankController.createPaper("Flower"."1000001921032"));
    System.out.println(questionBankController.createPaper("Doug"."1000001921051"));
    System.out.println(questionBankController.createPaper("大宝"."1000001921987"));
}
Copy the code

Results:

Candidate: Huahua Test Number:1000001921032-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- one or multiple choice questions The first1A: JAVA2 EE B: JAVA2 Card C: JAVA2 ME D: JAVA2 HE E: JAVA2 SE2C: The name of the class must be the same as the name of the class. D: The name of the class must be the same as the name of the class. If there is only one statement in the main method of A JAVA program, use {}(curly braces). A first3A: Variables are randomly composed of letters, underscores, digits, and $symbols. B: Variables cannot start with a number; C: A and A are the same variable in Java; D: Different types of variables can have the same name. B4A: STRING B: x3x; C:voidD) de$f5Problem: Expression (11+3*8) /4%3The value of is A:31B:0C:1D:2D1How many legs does a little red horse and a little black horse have?4The first leg2Answer: The head hurts the most3Problem: what bed can't sleep answer: gum first4Question: Why don't the good horse eat back grass answer: The grass is gone1000001921051-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- one or multiple choice questions The first1A: JAVA2 EE B: JAVA2 Card C: JAVA2 ME D: JAVA2 HE E: JAVA2 SE2C: The name of the class must be the same as the name of the class. D: The name of the class must be the same as the name of the class. If there is only one statement in the main method of A JAVA program, use {}(curly braces). A first3A: Variables are randomly composed of letters, underscores, digits, and $symbols. B: Variables cannot start with a number; C: A and A are the same variable in Java; D: Different types of variables can have the same name. B4A: STRING B: x3x; C:voidD) de$f5Problem: Expression (11+3*8) /4%3The value of is A:31B:0C:1D:2D1How many legs does a little red horse and a little black horse have?4The first leg2Answer: The head hurts the most3Problem: what bed can't sleep answer: gum first4Why doesn't the good horse eat the grass back?1000001921987-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- one or multiple choice questions The first1A: JAVA2 EE B: JAVA2 Card C: JAVA2 ME D: JAVA2 HE E: JAVA2 SE2C: The name of the class must be the same as the name of the class. D: The name of the class must be the same as the name of the class. If there is only one statement in the main method of A JAVA program, use {}(curly braces). A first3A: Variables are randomly composed of letters, underscores, digits, and $symbols. B: Variables cannot start with a number; C: A and A are the same variable in Java; D: Different types of variables can have the same name. B4A: STRING B: x3x; C:voidD) de$f5Problem: Expression (11+3*8) /4%3The value of is A:31B:0C:1D:2D1How many legs does a little red horse and a little black horse have?4The first leg2Answer: The head hurts the most3Problem: what bed can't sleep answer: gum first4答案 : why don't good horses turn their backs0
Copy the code
  • These are the papers for the three exams;Flower flower,doug,dabaoThe content of everyone’s test paper is the same, which is no problem, but the questions and choice order of the three people are the same, which does not meet the disorderly order requirement that we want.
  • And the above code is very difficult to expand, with the continuous increase of topics and the supplement of out-of-order functions, this code will become more and more chaotic.

Prototype mode refactoring code

The next step is to use the prototype pattern for code optimization, which is a minor refactoring.

The prototype pattern mainly solves the problem of creating a large number of duplicate classes, and the scenario we simulated requires the creation of the same test papers for different users, but the questions of these test papers cannot be easily fetched from the library every time, and sometimes even from remote RPCS. All of this is time consuming and can seriously affect efficiency as more objects are created.

One of the most important tools needed in prototype mode is cloning, which implements the Implements Cloneable interface in any class that needs it.

1. Engineering structure

itstack-demo-design-4-02└ ─ ─ the SRC ├ ─ ─ the main │ └ ─ ─ Java │ └ ─ ─ org. Itstack. The demo, the design │ ├ ─ ─ util │ │ ├ ─ ─ Topic. Java │ │ └ ─ ─ TopicRandomUtil. Java │ ├ ─ ─ QuestionBank. Java │ └ ─ ─ QuestionBankController. Java └ ─ ─ the test └ ─ ─ Java └ ─ ─ org. Itstack. Demo. Design. The test └ ─ ─ ApiTest.javaCopy the code

Prototype pattern model structure

  • The project includes the core question bank classQuestionBank, the question bank is mainly responsible for assembling each question and finally output the test paper.
  • For each test paper will use the clone way to copy, copy the test paper and the answer to each question out of order processing. Toolkits are provided here;TopicRandomUtil

2. Code implementation

2.1 Topic Options Out of order operation toolkit

/** * unordered Map elements, record the corresponding answer key *@param* option subject@paramThe key answer *@return{A=c., B=d., c = A., d = B.} */
static public Topic random(Map<String, String> option, String key) {
    Set<String> keySet = option.keySet();
    ArrayList<String> keyList = new ArrayList<String>(keySet);
    Collections.shuffle(keyList);
    HashMap<String, String> optionNew = new HashMap<String, String>();
    int idx = 0;
    String keyNew = "";
    for (String next : keySet) {
        String randomKey = keyList.get(idx++);
        if (key.equals(next)) {
            keyNew = randomKey;
        }
        optionNew.put(randomKey, option.get(next));
    }
    return new Topic(optionNew, keyNew);
}
Copy the code
  • You may remember from the previous section that we provided Map to store the question options and the key property to store the answers.You can flip it up if you forget
  • What this tool class does is it takes the selection from the Map out of order,So that's what A gives to B.B's possibilities go to CAnd record the position information of the correct answer after processing.

2.2 Cloning Object Processing Classes

public class QuestionBank implements Cloneable {

    private String candidate; / / the candidate
    private String number;    / / candidate number

    private ArrayList<ChoiceQuestion> choiceQuestionList = new ArrayList<ChoiceQuestion>();
    private ArrayList<AnswerQuestion> answerQuestionList = new ArrayList<AnswerQuestion>();

    public QuestionBank append(ChoiceQuestion choiceQuestion) {
        choiceQuestionList.add(choiceQuestion);
        return this;
    }

    public QuestionBank append(AnswerQuestion answerQuestion) {
        answerQuestionList.add(answerQuestion);
        return this;
    }

    @Override
    public Object clone(a) throws CloneNotSupportedException {
        QuestionBank questionBank = (QuestionBank) super.clone();
        questionBank.choiceQuestionList = (ArrayList<ChoiceQuestion>) choiceQuestionList.clone();
        questionBank.answerQuestionList = (ArrayList<AnswerQuestion>) answerQuestionList.clone();

        // The topic is out of order
        Collections.shuffle(questionBank.choiceQuestionList);
        Collections.shuffle(questionBank.answerQuestionList);
        // The answers are out of order
        ArrayList<ChoiceQuestion> choiceQuestionList = questionBank.choiceQuestionList;
        for (ChoiceQuestion question : choiceQuestionList) {
            Topic random = TopicRandomUtil.random(question.getOption(), question.getKey());
            question.setOption(random.getOption());
            question.setKey(random.getKey());
        }
        return questionBank;
    }

    public void setCandidate(String candidate) {
        this.candidate = candidate;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    @Override
    public String toString(a) {

        StringBuilder detail = new StringBuilder("Candidate:" + candidate + "\r\n" +
                "Test Number:" + number + "\r\n" +
                "--------------------------------------------\r\n" +
                1. Multiple choice questions + "\r\n\n");

        for (int idx = 0; idx < choiceQuestionList.size(); idx++) {
            detail.append("The first").append(idx + 1).append("Question:").append(choiceQuestionList.get(idx).getName()).append("\r\n");
            Map<String, String> option = choiceQuestionList.get(idx).getOption();
            for (String key : option.keySet()) {
                detail.append(key).append(":").append(option.get(key)).append("\r\n");;
            }
            detail.append("Answer:").append(choiceQuestionList.get(idx).getKey()).append("\r\n\n");
        }

        detail.append(2. Essay Questions + "\r\n\n");

        for (int idx = 0; idx < answerQuestionList.size(); idx++) {
            detail.append("The first").append(idx + 1).append("Question:").append(answerQuestionList.get(idx).getName()).append("\r\n");
            detail.append("Answer:").append(answerQuestionList.get(idx).getKey()).append("\r\n\n");
        }

        returndetail.toString(); }}Copy the code

There are three main operation contents, respectively;

  • twoappend()The addition of each topic is similar to the way we used in builder mode, adding decoration materials.
  • clone()The core operation here is the copy of the object, which includes not only itself, but also both collections. Only such a copy can ensure that the operation of the cloned object does not affect the original object.
  • Out of order operation, inlistThere’s a method in the set,Collections.shuffle, you can scramble the order of the original set and output a new order. Here we use this method to do out-of-order operations on the questions.

2.4 Initializing test paper Data

public class QuestionBankController {

    private QuestionBank questionBank = new QuestionBank();

    public QuestionBankController(a) {

        Map<String, String> map01 = new HashMap<String, String>();
        map01.put("A"."JAVA2 EE");
        map01.put("B"."JAVA2 Card");
        map01.put("C"."JAVA2 ME");
        map01.put("D"."JAVA2 HE");
        map01.put("E"."JAVA2 SE");

        Map<String, String> map02 = new HashMap<String, String>();
        map02.put("A"."The Main method of a JAVA program must be inside a class.");
        map02.put("B"."JAVA programs can have multiple main methods.");
        map02.put("C"."Class names must be the same as file names in JAVA programs.");
        map02.put("D"."If there is only one statement in the main method of a JAVA program, it can be enclosed without {}(curly braces).");

        Map<String, String> map03 = new HashMap<String, String>();
        map03.put("A"."Variables are randomly composed of letters, underscores, digits, and $signs;");
        map03.put("B"."Variables cannot start with a number;");
        map03.put("C"."A and A are the same variable in Java;");
        map03.put("D"."Different types of variables can have the same name;");

        Map<String, String> map04 = new HashMap<String, String>();
        map04.put("A"."STRING");
        map04.put("B"."x3x;");
        map04.put("C"."void");
        map04.put("D"."de$f");

        Map<String, String> map05 = new HashMap<String, String>();
        map05.put("A"."31");
        map05.put("B"."0");
        map05.put("C"."1");
        map05.put("D"."2");
        
        questionBank.append(new ChoiceQuestion("Not included in the version defined by JAVA", map01, "D"))
                .append(new ChoiceQuestion("What is true of the following statement?", map02, "A"))
                .append(new ChoiceQuestion("What is true about variable naming conventions?", map03, "B"))
                .append(new ChoiceQuestion("The following () is not a valid identifier",map04, "C"))
                .append(new ChoiceQuestion("The expression 11 plus 3 times 8 over 4% is equal to 3.", map05, "D"))
                .append(new AnswerQuestion("How many legs did a little red horse and a little black horse have?"."Four legs"))
                .append(new AnswerQuestion("Iron or wood?"."The worst headache"))
                .append(new AnswerQuestion("What bed you can't sleep in?"."Jaws"))
                .append(new AnswerQuestion("Why doesn't a good horse turn its back?"."The grass is gone in the back."));
    }

    public String createPaper(String candidate, String number) throws CloneNotSupportedException {
        QuestionBank questionBankClone = (QuestionBank) questionBank.clone();
        questionBankClone.setCandidate(candidate);
        questionBankClone.setNumber(number);
        returnquestionBankClone.toString(); }}Copy the code
  • The content of this class is relatively simple, mainly provides the mode initialization operation of the content of the test paper.All examinee papers are the same, the question order is not consistent).
  • As well as external to provide the method of creating papers, in the process of creating using the way of cloning;(QuestionBank) questionBank.clone();And finally return the test paper information.

3. Test and verify

Writing test classes:

@Test
public void test_QuestionBank(a) throws CloneNotSupportedException {
    QuestionBankController questionBankController = new QuestionBankController();
    System.out.println(questionBankController.createPaper("Flower"."1000001921032"));
    System.out.println(questionBankController.createPaper("Doug"."1000001921051"));
    System.out.println(questionBankController.createPaper("大宝"."1000001921987"));
}
Copy the code

Results:

Candidate: Huahua Test Number:1000001921032-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- one or multiple choice questions The first1A: JAVA2 Card B: JAVA2 HE C: JAVA2 EE D: JAVA2 ME E: JAVA2 SE2Problem: Expression (11+3*8) /4%3The value of is A:1B:0C:31D:2D3The following () is not A valid identifier A:voidC: STRING D: x3x; A4C: The main method of A JAVA program must be written inside A class. D: The name of the class must be the same as the name of the file. The first C5A: Variables are randomly composed of letters, underscores, digits, and $symbols. B: A and A are the same variable in Java; C: Different types of variables can be named the same; D: Variables cannot start with a number. D1How many legs does a little red horse and a little black horse have?4The first leg2Problem: what bed can't sleep answer: gum first3Answer: The head hurts the most4Question: Why don't the good horse eat back grass answer: The grass is gone1000001921051-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- one or multiple choice questions The first1A: A JAVA program can have more than one main method B: A JAVA program's main method must be written inside the class C: A JAVA program's main method must not be enclosed in {}(curly braces) D: A JAVA program's class name must be the same as the file name The first B2Problem: Expression (11+3*8) /4%3The value of is A:2B:1C:31D:0A3The following () is not A valid identifier A:void(C: d, C $d; D: STRING4A. JAVA2 Card B: JAVA2 HE C: JAVA2 ME D: JAVA2 EE E: JAVA2 SE5A: A variable cannot start with A number; B: A and A are the same variable in Java; C: Different types of variables can be named the same; D: Variables are randomly composed of letters, underscores, digits, and $signs. A1Problem: what bed can't sleep answer: gum first2Answer: The head hurts the most3Question: why good horse don't eat turn head grass answer: back of grass didn't first4How many legs does a little red horse and a little black horse have?4One-legged examinee: Dabao No. :1000001921987-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- one or multiple choice questions The first1The following () is not A valid identifier A: x3x; B: d, C: CvoidC) STRING D) STRING2Problem: Expression (11+3*8) /4%3The value of is A:31B:0C:2D:1C3A: Different types of variables can have the same name. B: Variables are randomly composed of letters, underscores, digits, and $signs. C: Variables cannot start with a number. D: A and A are the same variable in Java; C4C) The name of the class must be the same as that of the file name. D) The name of the class must be the same as that of the file name. C) The name of the class must be the same as that of the file name. The first B5A: JAVA2 EE B: JAVA2 Card C: JAVA2 HE D: JAVA2 SE E: JAVA2 ME 答案 : C1Question: why good horse don't eat turn head grass answer: back of grass didn't first2How many legs does a little red horse and a little black horse have?4The first leg3Problem: what bed can't sleep answer: gum first4Answer: The most painful headache is in the head0
Copy the code

As can be seen from the above output results, everyone’s questions and answers are in different and disorderly order, as shown in the following figure. – Huahua, Doudou, Dabao, everyone’s paper has questions and options in a chaotic order

Seven,

  • The above real-world scenario simulates the role of the prototype pattern in refactoring in development, but it is true that the prototype pattern is not used very often. If some special scenarios need to be used, it can also be optimized according to this design pattern.
  • Additional advantages of prototyping include; It is easy to clone complex objects, avoid repeated initialization operations, and do not need to be coupled to other classes that belong to the class. However, there are some disadvantages that can make this pattern extremely cumbersome if the objects include clones of circular references, as well as clones of deeply used objects in the class.
  • After all, design mode is a whole set of ideas, and reasonable application in different scenarios can improve the quality of the overall architecture. Never try to force design patterns, which can lead to over-design and wasteful development and maintenance costs as you address the changing needs of the business.
  • The early stage is code optimization, the middle stage is the use of design patterns, and the late stage is the construction of global services. Constantly strengthen their overall ability to control, but also deepen their processing of details. Up or down is the best way for a programmer to deal with it, and choosing the right one is the best choice.

Recommended reading

  • Java Development Architecture: Introduction to domain-driven Design DDD Landing
  • Java Development Architecture: DDD Model Domain-level decision Tree Service Design
  • Java development architecture: domain-driven design architecture builds microservices based on SpringCloud
  • Source code analysis | Mybatis interface has no implementation class why can add and delete execution
  • Be reasonable, as long as you are a programmer who love to toss about, graduation job really do not need to spend money training!