Source: Http://blog.csdn.net/lezhiyong
1 Problem 1.1 Project
More and more functions, more and more complex logic, more and more chaotic modules, more complex architecture
Problems:
1, module a message to other modules processing, B module-"forward message to C-" transfer to D "forwarded to a
2, the initial header file function definition is clear, the more to the back inside the more chaotic things.
3. The basic function is repeated in each module.
1.2 Humans developed
1, the previous code:
Can not understand the idea of the previous code, the new function into a set of systems.
Causes a lot of repetitive code and duplicate variables, resulting in named duplicates, conflicting functions, classes, and variables.
Case 1: Two istartrecorder, only the parameters are different.
Two istartrecorder, only the parameter is not the same, but a means to start the recording encoder, a start recording server, according to two function writing time, it is obvious that the latter does not understand the meaning of previous recorder and add the code. After the latter name adjustment to Istartrecordservice:
Case 2:
For one of the following projects:
The class with the ****IMPL.CPP flag, one that inherits the * * * * * * * * * * * * * * * * * * * * * * * * *, in this case it is easy to realize the combination/aggregation relationship between Rssmgrlmpl, Rssmanager, Crssimpl from the class instantiation process.
Rssmgrlmpl: Inherit Rmmanager, is to accept the implementation of the SIP signaling, is the creator of the Rssmanager.
Rssmanager: The manager of the recording task
Crssimpl: Is the creator of Crssavrecordermgr.
Crssavrecordermgr: A Recorder manager in the mission
When you need to create a new class, try to keep it consistent with previous ideas. (No advantages and disadvantages of the number of code added to the minority subject to the majority)
2, to their own code:
Bogey does not conform to the architecture used in the current project, using other methods that are familiar to them.
1, the use of general software specifications and mode design ideas.
2, to have their own ideas and innovative code to do the labeling, so that others understand.
Case:
Use recursive schemas with caution (recursive functions)
A video window realizes dual stream video (standard stream + low stream), which has already implemented standard flow
Class videocell//single-channel standard video processing logic
{
Public:
Video stream receive function
...
Private:
Standard flow variables
}
Class winvideocell//windows Video Window
{
Public:
How Windows operates on a video window
...
Private:
Videocell M_videocell;
}
Class winvideolayout//Video Panel
{
Winvideocell m_arrwincell[25];
}
Recursive method implementation:
Class Videocell//Video window
{
Public:
Standard Flow method
...
Private:
Standard flow variables
...
VideocellM_lowflowcell;
}
Cons: Videocell class function Call if not well controlled, will fall into the Videocell function recursive call Mihunzhen
Standard Implementation Method:
Class Winvideocell//windows Video window
{
Public:
How Windows operates on a video window
Private:
Videocell M_videocell;
Videocellm_lowflowcell;
}
3. Other frequently Asked Questions:
Data is passed in void * form and then shaped to the appropriate structure
Switch also has switch inside, this nesting way is the human brain difficult to crack
2 several principles 2.1 uniqueness principle
1. Library functions: Only used in one class
2, the same function only use an interface to provide external functions.
3, as long as the duplication of things as far as possible merger
The same feature is abstracted into a base class
The same method is abstracted into a virtual base class or the same interface
The same logic is abstracted into the same function
2.2 Consistency principle
1. Language and style in different modules, signaling structure, macro definition mode
2. The structure of allocation and release resources is consistent: used at the same code structure level, provided in the same class, and provided in the same CPP global function.
2.3 Principle of symmetry
1, named Symmetrical Start-stop,init-uninit,
function position symmetry
2, engineering structure symmetry, understand an engineering structure, other engineering structure is similar.
3.
3 How to do 3.1 person requirements
1, to their own code: continuous development, continuous improvement
2, to others code: from the perspective of the overall understanding of the previous code ideas, do not know before maintaining the status quo
3. Others to themselves: the inheritance of norms
3.2 Engineering Requirements
1. Head file care, architecture header file, supervised, submit audit
2, regular inspection and rectification, will go wrong door code back, the code to correct the violation
3, new understanding of the project structure and head file
Several principles to create efficient code maintenance