What Is Modular Programming?
Modular program design refers to dividing a large program into several small program modules according to functions during program design. Each small program module completes a certain function, and establishes the necessary relations between these modules. Cooperative programming method for the entire function. [1]
- When designing more complicated programs, a top-down approach is generally used to divide the problem into several parts, and each part is refined until it is decomposed into a better solution. Modular design, simply put, is that the writing of the program is not to enter computer statements and instructions one by one from the beginning, but first to describe the main structure and process of the software using the main program, subroutine, subprocess and other frameworks, and to define and debug As the input and output link relationships between the various frameworks are gradually refined, the result is a series of algorithm descriptions in functional blocks. The method of programming a function block as a unit, and implementing its solution algorithm is called modularization. The purpose of modularization is to reduce the complexity of the program and simplify the operations of program design, debugging, and maintenance.
- use
- The complex problem is divided into separate modules, which is called modular design. Generally speaking, the modular design should follow the following main principles:
- 1. Module independent
- The principle of module independence is manifested in that modules complete independent functions, and the connection with other modules should be as simple as possible, and each module has relative independence.
- 2. The size of the module should be appropriate
- The size of the module cannot be too large or too small. If the function of the module is too strong, the readability will be poor, and if the function of the module is too weak, there will be many interfaces. Readers need to accumulate experience through more programming.
- 3 Pay attention to levels when decomposing modules
- In multi-level task decomposition, attention should be paid to abstracting the problem. In the early stage of decomposition, only large modules can be considered, and in the medium stage, it is gradually refined and broken down into smaller modules for design. [2]
- Modular programming can be performed using the following steps:
- Analyze the problem and identify the tasks that need to be solved;
- The task is decomposed and refined step by step, divided into several sub-tasks, each sub-task only completes part of the complete function, and can be achieved through functions;
- determine the calling relationship between modules (functions);
- optimize the calling relationship between modules;
- in
- The basic idea of modular program design is top-down, gradual decomposition, divide and conquer, that is, a larger program is divided into small modules according to functions, each module is relatively independent, single function, clear structure, simple interface.
- Other advantages of modular programming are as follows:
- (1) Control the complexity of programming.
- (2) Improved code reuse.
- (3) Easy to maintain and expand functions.
- (4) Conducive to team development. [3]