Article Directory
1. Structured programming method for process-oriented programming
If you use a process-oriented language (such as: C language) to develop large-scale projects, you generally use structured programming methods;
1. The concept of structured programming method
The design idea of the structured programming method is as follows:
- Top-down, divide and conquer;
- Decompose functions, each function abstracts a functional module;
As shown in the figure below, the structured programming method is to decompose a large problem into many small problems, each small problem is solved by an independent sub-module, and multiple sub-modules together form a large software system;
2. Characteristics of structured programming method
The program structure designed using the above ideas has the following characteristics:
- It is a tree structure, each leaf node is a basic functional module;
- The functions of the modules are independent , and each module is equivalent to a subroutine. To call a module is to call the subroutine;
- There are only sequence, selection, and loop code logic inside the module ;
3. Advantages and disadvantages of structured programming method
The advantage of structured programming is that it can split a complex and huge system into several subtasks, which is convenient for development, control and maintenance;
Structured programming also has many disadvantages:
- Poor reusability: the code of each module subroutine is basically not reusable;
- Poor data security: Without data security, developers can access any variable of any function at will;
- Not suitable for developing graphical interface: It is difficult to describe and realize the things of graphical interface using procedural language , even if it is developed, it is not easy to maintain; therefore, many programs in C language are command-line programs, such as: ffmpeg, etc.;
- Separation of data and processing: data (variables) and processing (methods) are defined in different places in the module , which brings a lot of trouble to code maintenance;
- Poor maintainability: Once the data structure changes, a lot of code needs to be modified;
Second, the introduction of object-oriented programming
In view of the above shortcomings of process-oriented programming, the idea of object-oriented programming is introduced here;
For the problem of "separation of data and processing" , object-oriented can define the data of things and the processing of data in a class, and encapsulate them together;
To solve the problem of "poor reusability" , in object-oriented, for the same type of things, abstract their common characteristics to form a class , which can be reused and create multiple things of this type;
For the problem of "not suitable for developing graphical interface" , it is very troublesome to abstract the interface elements in process-oriented, but if you use object-oriented, you can directly abstract the interface into a class, and the buttons and other elements in the interface can also be abstracted into a class. The combination of class objects is a graphical interface program;
For the problem of "poor data security" , in object-oriented, when encapsulating data and methods, each member will be assigned an accessible range , such as public, protected, private and other access ranges, and private members cannot be accessed externally;
After the introduction of object-oriented, the maintainability of the program is greatly improved;