OO_ Unit1 summary

Time:2022-2-14

1、 Program structure analysis

First job

1. Design conception and self-evaluation

  The difficulty of the first operation is not too high. We only need to analyze the expression simply combined by constant and power function. Each item can be regarded as a fixed form of coef * x * * index. The term class containing the two biginger attributes of coef and index is established as the most basic data structure, and the method of single derivation is realized. Implement the construction, overall derivation and simplification after reading the expression in termlist.

Since the title indicates that white space characters have no effect on format judgment, all white space characters can be removed when reading the expression to simplify the operation of splitting the expression. When parsing the expression, I first tried the method of finite state machine and read it by character. However, this method is easy to make mistakes due to too complex and too many states in subsequent operations, which has been replaced by other methods. When simplifying, you only need to compare whether the coefficients of the two terms are the same.

  Due to the lack of consideration of subsequent function addition and more complex parsing processing, this operation adopts an inappropriate processing method, which is not scalable enough, and the reconstruction in subsequent operations takes more time. And the embodiment of object-oriented thinking is not enough.

 

2. Measurement tool analysis

UML class diagram:

Complexity and coupling

  Because the main functions are implemented in termlist, the complexity and coupling of termlist class are relatively high.

Second operation

1. Design conception and self-evaluation

  This job is not much different from the last one, and the requirements for trigonometric functions sin (x) and COS (x) are added. Therefore, each term can be regarded as the format of coef * x * * xindex * sin (x) * * sindex * cos (x) * * cindex. Each term requires four parameters. Here, I wrap each factor into a separate class and implement the term structure in a combined way. The rest of the structure basically continues the practice of the previous operation.

  Similarly, since white space characters have no effect, all white space characters are removed when reading the expression. There is a big difference in the step of analytical expression. Considering the significant increase of complexity, I give up the analytical method of finite state machine and adopt the method of regular expression. Match whether the whole formula conforms to the format by constructing a large regular expression (the large regular expression is composed of many small regular expressions added hierarchically to ensure readability and reusability). The small regular is used to extract each item and factor from the expression to instantiate term and add it to termlist.

  The idea of derivation is basically the same as that of the last operation. The overall derivation is transformed into the sum of each derivation, which is stored in ArrayList or HashMap according to the formula. When simplifying, first compare whether the three indexes of the two terms are the same, then consider the cases of sin (x) * * 2 + cos (x) * * 2 = 1 and X * * 2 = x * x, and traverse the combined output.

2. Measurement tool analysis

UML class diagram

 

Complexity and coupling

  Due to a more object-oriented approach than the last job, the complexity and coupling are improved. However, since the main functions are not encapsulated separately, but integrated into term or termlist classes, there is still room for improvement.

The third operation

1. Design conception and self-evaluation

  The difficulty of this operation has been greatly improved. The addition of nested parentheses brings the problem of iteration, which means that the previous analysis and derivation methods are no longer applicable and need to be greatly changed. But there are also some that can be reused. Due to insufficient time and thinking before writing code, the design of object-oriented idea can not be well reflected. Finally, the expression binary tree is selected to establish the data structure. In this assignment, I will refine the expression into binary operation between factors. Each node of the expression tree is an operation or factor (leaf node), and the nesting of trigonometric functions is also regarded as an operation.

  When parsing the expression, it is subdivided into the combination of factor and operation, which avoids the emergence of large regularity and is only used to extract different factors. Using the idea of stack, the priority of each operation is defined, and the expression binary tree is constructed. Because the check format and binary tree are difficult to combine, I integrate the check format operation into a class separately, and check it before constructing the number.

  For example, it is necessary to simplify the operation of adding and subtracting constants between 0 generations, and avoid the unnecessary addition and subtraction of constants between 0 generations.

  The establishment of expression tree has good adaptability to the analysis of complex operations, clear thinking and certain reusability. The main defect is that the format checking logic is a little confused, which is not well connected with the tree structure. In addition, due to the lack of time, there is still a large optimization space for the simplification of output results.

2. Measurement tool analysis

UML class diagram

 

Complexity and coupling

  Due to the increasing difficulty of this operation, the situation is changeable and the operation is more complex. I don’t have a good implementation hierarchy. Too many methods are implemented in a few classes, resulting in unsatisfactory complexity and coupling. I should better conceive my design before typing the code.

2、 About bugs

Bug analysis

  In the first two operations, their own bugs mainly appear in the judgment of WF. Special circumstances are not taken into account. In fact, they are easy to avoid. The third operation also crossed the boundary. With the increase of complexity, the grasp of details is not in place, and there is still no patience to fully test and comprehensively consider the problems, resulting in many bugs.

test

  I didn’t find too many bugs in the mutual test, in part because I didn’t build a good evaluation program, resulting in low test efficiency, but I still summarized the following common test ideas.

  a.Mindless uses the data generator to generate data covering a wide range of functions and conduct black box testing to quickly find bugs.

  b.Try to make mistakes and boundary values that are easy to make when you finish your homework.

  c.Read each other’s code and find out the error logically.

3、 Comparison and experience

  As a newcomer, there are still some maladjustments from process-oriented to object-oriented, and many ideas need to be changed. I heard about the horror of OO before, and now I feel it deeply. However, the greater the challenge, the more we will gain from overcoming it.

  The difficulty of three homeworks gradually increases. Constantly consulting the new Java syntax, learning the use of new containers, and understanding factory and other design patterns make me slowly change to the right track of object-oriented. Seeing the design of big guys through various channels, I can only feel ashamed. My own code is still too childish. Whether it’s architecture, optimization or bug rate, I still have a lot of room for progress, and there’s still a lot to learn. In future assignments, I will pay more attention to the object-oriented way of thinking, invest more energy in architecture design, and achieve good scalability, high cohesion and low coupling in the real sense.

  Since I have chosen the distance, I only care about the wind and rain. Get ready for the next challenge.

Recommended Today

2021 impressed me deeply & wonderful bug / defect / problem record

Since November 2021, this article has experienced some impressive and wonderful bugs. The more you summarize, the more you grow! Common progressContinuous updateI also hope the bosses will give more suggestions image.png Conclusion: I didn’t think of relevance. I thought it would be ok if the test would not report an error according to the […]