Twenty-four chapters reconstruction

About reconstruction

Reconstruction of the definition:

  1. Without changing the external behavior of the software provided, it changes its internal structure, to make it easier to understand to be modified;
  2. The possible a program into multiple components.

Reasons for reconstruction

  • Code duplication;
  • Lengthy routine;
  • Too long or too deep nested loop;
  • Class interface failed to provide a consistent level of abstraction;
  • It has too many parameters list of parameters;
  • Review inner class is often limited to a part;
  • Changes lead to the same modifications to the plurality of classes;
  • The same changes to the system of inheritance;
  • caseStatements need to do the same modifications;
  • At the same time the relevant data used did not like the way the organization;
  • Class member functions using other features even more features than the use of their own class;
  • Excessive use of the basic data types;
  • A class doing nothing;
  • Transmitting a series of data subroutine stray;
  • Middleman objects have nothing to do;
  • A relationship similar to other classes too close;
  • Subroutine named improper;
  • Data member is set to be common;
  • A derived class uses only a small part of the base class member function;
  • Note codes are used to explain difficult;
  • The use of global variables;
  • Before using the setup code subroutine call or after the call using the finishing codes;
  • The program seems to be some code that will be used at some point in the future.

Specific reconstruction

Data-level reconstruction

  • Constant alternative name appliances mysterious value;
  • The variable names more clearly and deliver more information;
  • Indicating inlined;
  • Instead a function expression;
  • Introducing the intermediate variable;
  • Instead of a plurality of single-use multipurpose variables variables;
  • Local variables used in the topical use instead of the parameter;
  • The basic data types into a class;
  • The group type code into a class or enumerated type;
  • Converting a group type code is a base class and derived classes corresponding;
  • Converting the number of group objects;
  • The encapsulated cluster;
  • Class data to replace conventional recording.

Statement-level reconstruction

  • Decomposition of Boolean expressions;
  • Complex Boolean expressions to convert into a table named accurate Boolean function;
  • Duplicated code fragments of different conditional statements combined portion;
  • Use breakor returnnot the loop control variable;
  • In nested if-then-elsestatements Once you know the answer to return immediately, rather than assign a return value;
  • Polymorphism replaced with conditional statements;
  • Creating and using nullobjects instead of to detect a null value.

Subroutine-level reconstruction

  • Or a method of extraction subroutine;
  • The inside of the subroutine biphenyl;
  • Converting subroutine lengthy class;
  • Alternatively simple algorithm complexity algorithm;
  • Increase parameter;
  • Delete parameters;
  • The query operations independent from the modify operation;
  • Merging similar subroutine, distinguishing their function parameter;
  • The behavior depends on the parameters of the subroutine split open;
  • Pass an entire object rather than a particular member;
  • Pass specific member instead of the entire object;
  • The packaging operations downcast.

Class implements operations

  • The value of the reference object into the object;
  • Virtual function instead of the initialization data;
  • Changing the position of the member function or a data member;
  • The code extraction number Laid derived class;
  • The code is similar to the combination is placed in the base class.

Reconstruction of class interface

  • The member functions of the class into another;
  • A class into two;
  • Delete class;
  • Remove trust relationships;
  • Remove the middleman;
  • With the commission instead of inheritance;
  • The introduction of an external member function;
  • Extended by the introduction;
  • Member variable of encapsulating exposed;
  • For class member can not be modified, deleted the relevant Set()member function;
  • Hide those member functions can not be used outside the class;
  • Package does not use the member function;
  • Very similar to those achieved merging the base and derived classes.

System-level reconstruction

  • Create a clear index of the source data can not be controlled;
  • The class one-way links instead of class two-way link; the two-way link to group class one-way links;
  • Factory Method pattern rather than a simple constructor;
  • Substituted with exception error handling code, converting or do the opposite direction.

Security reconstruction

  • Save initial code;
  • Please smaller pace of reconstruction;
  • The list of things to do to a bar;
  • Set a parking lot;
  • More use of the checkpoint;
  • The use of compiler warnings;
  • retest;
  • Increase test cases;
  • Check the modification of the code;
  • According to reconstruct reconstruction method to adjust the level of risk;

The case should not be reconstructed

  • Do not change synonymous after reconstruction as almost;
  • Instead of using reconstituted avoid overwriting.

Reconstruction strategy

  • Reconstructed in increasing routine;
  • Add to reconstruct the class time;
  • Reconstruct the defect at the time of repair;
  • Watch easy-to-module error;
  • Focus on highly complex modules;
  • Your hands are working to improve the code in the preservation of the environment;
  • Clean, clearly defined boundaries between the code and the code is bad, then try to move the code through this border.

Points

  • Modify the things you have to face a lifetime of the program ,, including not only the initial development stage, including after the initial release;
  • In either modify the software quality in the well, or worse. The first law of software evolution is the evolution of the code should enhance the intrinsic quality of the program;
  • The key to success lies in the reconstruction of many programmers should learn the warning code requires attention to those marking the reconstruction;
  • Another element of the success of the reconstruction is the programmer should master a large number of specific reconstruction method;
  • The last point is that the success of the reconstruction of reconstruction have security policies;
  • Reconstruction of the development phase is the best time to enhance the quality of the program, because you can make change instantly just produce dreams into reality.

Guess you like

Origin www.cnblogs.com/liam-ji/p/11569082.html