VI. Modular Specification:
In order to improve the reusability of software, the workload of repetitive development is reduced. At the same time, in order to improve the readability of the program and facilitate the maintenance of the program, the modularization of the software must be strengthened. Modularity should follow these basic specifications:
1, a function should be fine and small, the function of the code should be controlled in a modest scale, the code for each function can not be more than 150 lines, if more than this size, should be modular work. For some special functions that do take more than 150 lines, they should be submitted for discussion, after which the writer is asked to comment on the function in more detail, and to specify the reason for the function Super row, as well as design ideas.
2, a certain function, if repeated implementation of more than three times, should consider the modular, write it as a common function. and publish it to the developer. and requires the interface document and implementation of the functions of the record.
3. Each developer should use the ready-made modules of others as much as possible to reduce the duplication of development.
4, the function of the modular, to consider the function of the hierarchical relationship, especially in the addition of new functional modules, the original function code to be carefully adjusted to do the same function of the different functions do not have duplicate code, this requirement is to facilitate code maintenance. Examples are as follows:
The following functions exist:
//从szFileName文件中取 ......
long ...... cmGetSomething(const char * c_szFileName,......)
{
CFile * pFile;//用来保存打开文件的地址
pFile=new CFile(c_szFileName,CFile::modeRead);//用创建一个只读文件
if(pFile==NULL)
{
lResult=CM_POINT_IS_NULL;
goto END;
}
//从文件中读取......
......
//关闭文件
delete pFile;
END:
return lResult;
}
If you need to add a new function for the following interface now:
long ...... cmReadSomething(CFile * pFile)
{
if(pFile==NULL)
{
lResult=CM_POINT_IS_NULL;
goto END;
}
//从文件中读取......
......
END:
return lResult;
}