Object-oriented design and construction - the first unit operation summary

to sum up

The main contents of the first unit operation is a polynomial derivation, although it is a relatively common programming examples, but because I write a program for cognitive architecture is zero, coupled with a limited investment of time on the job three times, resulting in programming when encountered many problems, now inadequate to reflect on these three operations.

The main point of reflection can be divided into the following points, which will be reflected from the job after the analysis.

  • Code rewrite problem

    Here rewrite includes two aspects:
    the reconstruction between different jobs first, because I only consider the current implementation of the tasks in the job when the idea, but never to expand been thinking of the code, leading to a time when publishing a new job, we have found the required infrastructure and far from existing infrastructure, and therefore had to overthrow the existing design, repetition coding, wasting a lot of time. However, because each job task content was unknown, even exhausting to think about expansion does not necessarily make the job performance of the code was to meet the requirements of the next, so they will be able to think of the idea only after advance viewed on github behind several jobs may require to over prepare in advance.
    The second is known broad framework of the process of writing code, because the first time the idea did not want to know the details until the beginning of truly finding may want to add a lot of new functions, or write to write later found to have a function can not meet requirement, then the previous code to re-add complement. Such behavior is very dangerous, because this approach is equivalent to a function may be added before the branch basis, plus the time factor may be forgetting some of the details of the function to be added easily result in the addition of new bug, increase the difficulty of code maintenance. That functional approach failed to adequately well in advance of thinking.

  • Functional relationship is unclear issues

    One function of cognitive errors of their class. Coming at the wrong class to implement the corresponding function, completely ignoring the "objectivity" of the programming mode, thinking of writing a function to be able to meet the function; also it is time to write a function or thinking beyond the scope of the class itself belongs scope, such as thinking when calling this function belongs to the class of the preparation and realization of it, which is part of the preparation of this function is to ignore the default preconditions like this will increase the difficulty of writing, will increase the thinking of different functions in the preparation coupling between, and prone bug.
    Second, the error between the function calling convention. Call the function should try to adopt the principle of individual calls that big a function call small functions, try to avoid A calls B, and B can also call the function of case A, or will increase the circle of extreme complexity of the function.
    Third, the coupling between the function of cognitive errors. The called function should ignore the situation may be called, should be required only to think the conditions are assumed to set up, and then write only on the basis of existing conditions. The calling function should create the necessary environment for the called function in advance. In carrying out this function can be maintained low, coupling and function of other factors.

  • A quiz to test the entire program, while ignoring the completeness test of individual functions

    After three operations of this code is written per capita, the most whole code writing test program. But for the entire program, every function has a certain possibility, the possibility of multiplying the number of functions, the difficulty of the test will be increased dramatically, together with their own structure test data is limited, so the idea of ​​testing the entire program itself is wrong. But for a function, in the case that has been a prerequisite for the function of a function to be tested is relatively easy, and relatively easy to achieve complete set of tests, which reduces the potential for the bug is very helpful.

  • Error process of establishing the framework

    I am in the process of writing three jobs, they did not establish the appropriate framework for understanding, especially prepared for the first job, really started to write after reading the subject directly, thus resulting in multiple re-writing the code behind when write. Way to build the architecture of the current can think of are as follows: first
    to write one of the most simple test sample, conduct a simulation of the entire process, in order to determine the call over the relationship between architecture and its main class with. Then write multiple different types of test cases to determine the number of branch function on the main structure. This can speed up the establishment of the code architecture, but also to reduce the direct overhand discovery schema error.

  • Discuss the issue activity

    I write code in the process, basically "not muffled fortune", rarely communicate with others, including a discussion with the students is not active, read the forum posts are numbered, and so on. But like this daunting task, discussion and exchange is valuable, the collision of thinking can sometimes tend to think hard for a long time to solve your problem. Because this little exchange, not only lost the opportunity to fix a bug, lost the opportunity to learn from others architecture, did not even catch the shuttle using automatic evaluation machine such a valuable tool. And discussions failed to drive less enthusiasm written, will lead to my third day to finish the job on Thursday, Friday and Saturday night and during the day did not meet again Code, Saturday afternoon whim suddenly go on a radical architecture reform. The results can be imagined, the final deadline also failed to complete the modifications, this can only be helpless can barely measured by garbage codes to pay up, the results are not surprising strong side, very unsatisfactory.


Specific analysis of three jobs

the first time

  • Work requirements
    The first details of the job is relatively simple, the main content of the guide is simple polynomial function of solving
    the entire code of the implementation process can be divided into "expressions of reading" -> "derivation of the expression" -> "merger of similar items "->" expressions of output "four steps.
    This is because only one type of main functions of the power function is achieved relatively simple classes, only Power Function and containers can be mounted to a power function.
    Reading in the process requires only the method of writing a regular expression formal expressions described.
    Class and method implementation as shown below:
    firstmethod
  • Code defect

    One drawback of this code is guilty of the above "functional relationship is not clear" problem. For example, the output function, first of all understand the power function List is loaded container class variables in this program with quite an expression stored information of each of the power function, however List output function is really just a simple call to the power function classes after_deriva_printfunction, corresponding to the full responsibility to output power function class. However, such logic is actually implemented on is not feasible, because the structure, expression should be what kind of symbol is connected between a power function, a power function should not matter that should be considered, should be an expression, i.e. Class List things should be considered. However, the case of writing the job, in fact, increases the coupling between the function of thinking, as a function Variable class, even to consider the case on its storage class ---- List class, which will increase the Code writing difficult. You might think that such small problems seem understandable, but this kind of thinking in my second and third jobs to other application scenarios and they will give people a strange feeling awkward, especially to write a class the function feel sometimes unable to start ---- the main thing to consider is too much, leading to difficulties in the preparation of cases occur.

  • Code metrics

    homework1default1
    As can be seen, in addition to cyclomatic complexity Variable (i.e. Power Function) (CC) of a higher value, the better the rest.
    This is also the one hand, should permit the above code defects, be guilty of a "functional relationship is not clear," the problem, leading to the complexity of the function becomes higher, more difficult.

the second time

  • Work requirements

    The second work introduces the concept of factors and items, while the introduction of this basic trigonometric factor. Therefore, the complexity of the structure than the first time the job has been significantly improved.
    First thing to understand is that this is an "expression" -> "item" -> "Factor" deeply nested relationship, expression term is "and" relationship, key factor is "by" relationship.
    The whole process than the first time the job is not much change, but it adds a lot of internal functions. The whole process still is "an expression reads" -> "derivation of the expression" -> "merger of similar items" -> "Output expression" (in fact, the whole process is the work of three such)
    expression reads aspect, the pretreatment may be greatly simplified by the reading process, such as the sin (x) Sine convert, thereby avoiding conflicts with the power function trigonometric reading; may be implicit power law, as x into display the x ** 1, so that some will be less judgment.
    Derivation process more derivation function of the product, it should be noted that the guide post base class seeking conversion type, such as x ** 2 is a function of power class, the class entries will become after derivation.
    Code structure is as follows:
    second
    secondMethod1
    secondMethod2

  • Analysis of the Problems
    The first direct result of the amount DesigniteJava, back slowly analysis
    secondfault1
    secondfault2
    • The first question is rather special, does not belong to one of the above problems. That is shallow copy problem. From a debug problems found, that Item (item type) in the trigoncanMergefunction, that function does is to determine whether two conditions are satisfied optimization items combined, returns a Boolean value, however, during the debug, it was found run to completion after this function, expressions of entry will be somehow modified, and the beginning of this function is for two terms used to copy, and then through some operation to be judged, this code would have been logical point of view there is no problem the first copy, and then the operation will not affect the incoming parameters. However, due to my Item class method itself is a container, coupled with my judgment is very confusing, the container will be modified copy in the factor, so it was two different objects but managed by the same factor case this behavior, this time a container object, the elements will be modified ---- make another container object is very dangerous and difficult to detect.
      Therefore, the solution to this problem should be: add a method to clone each class of data management, such as with this program model as an example, Expression.clonebe able to call Item.clone, which can be called inside the element Constant.clone, sine.cloneand so on, so will be able from basic the type of cloning, thus avoiding the problem of conflict management elements.But this is not the time to sacrifice in exchange for the safety of a practice? You may degrade application performance.
    • The second question is committed "architecture design" error. Since the time of writing architecture failed to notice the arrangement of features Item container element, I selected only way the arrangement is a constant front, but behind the constant power function, trigonometric arrangement is indeed very confusing way, which also I resulted in the item achieved between some of the features, MergeInExpressionwhen combined, were determined for a number of possible factors in the location of an item, even in item merged MergeInItemthere have been such a complex is determined, resulting in some of my function block it is extremely bloated, because the situation elements at various locations within the terms of subparagraph it needs to be considered.In fact, the four-tuple that fully job position within the different types of items factor been ascertained by some constraints, such as the method we are usingI like architecture Although the overall functionality and less clear division of function blocks, but the actual operation time, can obviously find that some functions are not originally scheduled to be in good function block, it should be abstracted, so that not only every the difficulty of writing a function block is reduced, but the overall logic will be more clearer.
    • The third question is also committed is "a function of where to place the wrong" questions I most often committed. This issue may also reflect the DesigniteJava of "long stetement", the key question is will this confuse "object" characteristics of different classes, a method should be written with the function of the method to achieve the closest class, but in order to achieve additional hastily , special features, without hesitation added a new function to be placed into one of the most beneficial to the current write their own position, and process-oriented way of thinking what is the difference. For example, the job trigonCanMergefunction, was like that because trigonometric functions may consist of items and other factors, so in terms of trigonometric functions have to go to achieve the merger is not a more convenient, so Item class (item category) will be responsible for the corresponding full functionality, however, can not be combined to obtain trigonometric functions to complete the item out from the trigonometric coefficients back to an entry in combination with other factors? Maybe some of this will be somewhat cumbersome, but by the trigonometric class to implement their merger trigonometric functions will be even more natural look, that is, to achieve a logical method of contact with the class.
    • The fourth question is committed by the above-mentioned "non-single function call relationship" caused. This problem can be reflected by the DesigniteJava of "Complex method", marked yellow circle is the high complexity of the hardest hit. For failing to clarify the procedure to determine the call, sometimes even step of the cycle call will write, lead to calling relationships more complex, you should try calling the subordinate function at a higher level function, subordinate or subordinates to avoid the same level can sometimes appear higher calling Case.

the third time

  • Foreword

    The operation is the most complete failure of the time, the reason is the attitude of the job is not correct. Wednesday and Thursday had hastily written code, should spend more energy to carry out extensive testing of the code, however, I felt that covers most of the situation to construct the sample will be very troublesome, which is the above mentioned "test program "error problem, the amount of code is too large, too complex situation, and they want by ignoring the code characteristics, only from the perspective of the overall function of the start of the" black-box testing "to test the most part, this difficulty is very large, it is easy to people will try to restrain him. So I Thursday night and Friday and Saturday during the day have not touched the code is written. Saturday afternoon, I suddenly felt before writing their own infrastructure is very strange, so he decides to move some large functional blocks to be modified, but time was limited, was very impetuous, coupled with the write inefficient code afternoon, resulting in continuous himself wrote 6 hours did not modify the architecture is fully finished, and even pay up a semi-final, and what almost no code test conducted, it is a failure.
    To fight for the future to spend more energy on test code, the students asked a lot of experience in testing, in order to avoid such bad things like this from happening again.

  • Work requirements

    The jobs compared to the second operation, the biggest difference is the support for nested structure, expression appears factors, internal factors and trigonometric expressions may be factors. No doubt a lot of increase in the complexity of the structure.
    This caused a lot of problems.
    First, how to read your entry. There are two methods, one is to use a character automaton type of way to be read, but difficult to write in this way is extremely high, the need to clear themselves after adding a character all cases that may arise, it is easy to write leak or where there thinking errors, but also detrimental to the code bug detection and code modification. The second method is the method that I used, still continued the work on the two read method ---- regular expressions, but can not build a regular expression rules with recursion, so the subject of on-demand,Use magic to defeat magic!Use recursion to handle recursion. The key factor is the recursive term in expression, in subparagraph a factor, but it can be a factor expression. Then simply expressions of the first layer expression factor modification, change is a constant symbol, then the entire expression can be seen as an internal recursive entry for the expression of a constant, it can be treated, followed by internal processing the keys to recursively.
    The second is how the nested structure is simplified, which is also the second most critical work place. My situation due to poor infrastructure, an item may appear as follows: Item -> Expressions -> Item -> expression ...-> key, in fact, this term is equivalent to the nested inside the last item, but the form itself restricts many operations, such as the merger of similar items, etc., the key is this is a recursively nested, just can not get their original type by one or two non-recursive processing. Therefore, in the design of recursive method to find a way to eliminate this kind of nested recursive.
    The rest is handled much like the second job, needless to say.
    Due to the quality of the work submitted is very bad, so the structure shown below is not modified after the submission of the program:
    third
    thirdMethod1
    thirdMethod2

  • Analysis of the Problems

    Man of few words said, the first light DesigniteJava operating results, run behind the results were analyzed
    thirdfault1
    thirdfault2
    first of all the result improved slightly compared with the previous terms, although there are still many ways to block "Method Complex" very high, but only a the complexity of the construction method of Item 17, the other relatively uniform distribution of around 10. Unlike the previous job trigonMergemethods complexity risen to 22, and the MergeInItemcomplexity is 18 and the like. Although the "long statement" there, but there is a long Item constructor, but its function is relatively simple, relatively speaking, than the previous method of confusing features, but also slightly changed.
    But this issue is still a lot of work, which are more part of the problem and repeat the operation a second time, this part of it aside, take a look at the most obvious problems exposed in the third job is to "build relationships architecture error "problem:
    first clear facter interface is associated with the operation factor; factorset interface is packed in containers factor, which is the entry class and the expression of the class should implement the interface; simpleFactor realization of non-container factor, the methods by a constant factor, the power factor function, a trigonometric function factors.
    Three internally defined as follows:
    factor
    factorSet
    simpleFactor
    It now appears that these three methods defined internal interfaces is very bad. Such as classes in Factor inMerge(internal merge) A method according to logically should be placed in the interface factorSet, because only containers of a factor to achieve similar internal phases are combined, then just a moment later determined to be more convenient numberIt may not be easy, But simply the method of writing a Factor interface class, and now think of it a little bit and illegal. And derivein fact, no need to rewrite it again within factorSet SimpleFactor class and class, in fact, only need to operate to achieve the transformation of down time later.
    The remaining question a second time with more than repeat, here put aside the.

Bug analysis program

  • Second job: bug when detecting the mutual job is measured out, i.e. when combined trigonometric determination portion determines at least a special, common factor leading to extraction after two terms, under certain circumstances, well- due to the different type of trigonometric calculation will merge.
  • Third job: job very much the measured cross-detected bug, reasons said above clearance. Later, however, he said before the code can modify the schema through, but now still no code on the back for testing, bug is still unknown.

Others found that the policy program adopted by bug

This bug several times to look for others the program is not active.
The method is mainly used in black-box testing aimlessly, i.e. only some of the test data to construct by known standard functions, but obviously such a configuration is inefficient under.
Other methods include exchanges with students,(Actually reach out and party)The test data discussed for other people's code testing,(Critical nonetheless). There are also the result of the use of some other people ran out of automatic evaluation testing.(I was already a basket case)

Application object creation mode

  • Try to use interface belongs when it should be clearly defined method of interface types
  • For shallow copy problem, for each class to the basic data management method implemented clone

Compared with the feelings and experiences

In fact, feelings and experiences and reflect on the beginning of the article has been almost finished, and then re-described here:

  • By way of manual advance simulation to determine the architecture of the conception of the main frame, and then use a different test samples to determine a number of branch function.
  • When the function is defined to be met: the function as specific as a single function should have close links with the class the function belongs, try not to think beyond the scope of existing conditions, to make use of the principle of individual calls.
  • Code tests shall be carried out to test the function blocks, rather than testing the entire program.
  • After working with the students to actively discuss, multiple reference(Hand)Bigwigs of ideas, collision thinking and more

Guess you like

Origin www.cnblogs.com/miku-mylife/p/12535848.html