1. Process Oriented VS Object Oriented

Process-oriented

  1. Process-oriented is to analyze the steps needed to solve the problem, and then use functions to implement these steps step by step, and call them one by one when you use them.

  2. For example, playing Gomoku: The process-oriented design idea is to first analyze the steps to solve this problem: (1) start the game (2) black go first (3) draw the picture (4) judge the win or lose (5) turn to the white (6) draw the picture (7) Judge the winner or lose (8) Return to step (2) (9) Output the final result.

下五子棋{
    
    

	开始游戏();

	黑子先走();

	绘制画面();

	判断输赢();

	轮到白子();

	绘制画面();

	判断输赢();

	返回到 黑子先走();

	输出最后结果;

}

Object-oriented

  1. Object-oriented is a programming idea centered on "objects". The problem to be solved is decomposed into various objects. The purpose of creating an object is not to complete a step, but to describe an object in the entire problem-solving step. Attributes and behaviors. Object-oriented divides problems by function, not by steps.

Insert picture description here

to sum up

  1. Object-oriented is a high degree of physical abstraction (overall macro-analysis), and process-oriented is top-down programming (a step-by-step analysis)

Advantages : performance is higher than object-oriented, because the class calls need to be instantiated, the overhead is relatively large, and consumes more resources; such as single-chip microcomputer, embedded development, Linux/Unix, etc. generally use process-oriented development, and performance is the most important factor.
Disadvantages : no object-oriented, easy to maintain, easy to reuse, easy to expand

Advantages : easy to maintain, easy to reuse, easy to expand, because object-oriented has the characteristics of encapsulation, inheritance, and polymorphism, a low-coupling system can be designed to make the system more flexible and easier to maintain.
Disadvantages : performance is lower than process-oriented

  1. Give examples of the advantages and disadvantages of the two, such as adding the function of regret chess in the game of Gobang. In the process-oriented process, the entire steps from input to display to final judgment must be changed, and even the order of function calls must be changed. In object-oriented design, it is only necessary to add a backtracking function to the board system. Now, the attributes and behaviors of the black and white parties and the rule system do not need to be changed. This example illustrates the low correlation between codes in object-oriented programming (low coupling characteristics), which makes the code easy to reuse and extend. It also illustrates that process-oriented code has low reusability and poor scalability.

Guess you like

Origin blog.csdn.net/qq_44791484/article/details/115194254