Comparison between the process-oriented programming and object-oriented into

Comparison between the process-oriented programming and object-oriented into

 

In one example (e.g., cleaning the room) will be described procedure-oriented and object-oriented differences in the program flow.

Is to process-oriented programming as a thing to do , according to the completion of the steps, each step is a process. For example, someone to clean the room about it, we need to take a broom, then carefully clean everywhere, and finally the broom back into place.

Code implementation process:

 

Output:

 

Is to object-oriented programming as a thing (the equivalent of a whole thing), to the outside world, things are used directly, not to manage his internal situation. The program is to set things can do anything. In fact, a bit like the process-oriented things to put inside a. For still clean the room, for example, if in fact, process-oriented themselves to clean the room, so pay attention to the steps, and object-oriented if you just notice the cleaning robot to clean the room, that sends a message on it, as to how the cleaning robot, is not knew.

Code implementation process

 

operation result:

 

 

After the news by issuing a sweeping, After a child, (1,2,3) cleaning robot will report the results of your own.

Process-oriented: you get a broom to clean the room, the subject is you, take a broom, sweeping large, a series of actions that you need to own to complete;

Object-oriented: the cleaning robot body as an object, the equivalent of a living creature, robot take the initiative to clean up, as to how finished cleaning, not yours.

Therefore, the rookie our analysis, process-oriented, people are in work. Object-oriented, people create the equivalent of a robot to work.

The computer program stand point of view, the essence of object-oriented and process-oriented is understood:

  • Process-oriented programming as a series of computer program set of commands, i.e., the order of execution of a set of functions. To simplify programming, the process continues for the segmented into sub-function the function, i.e. a function of the bulk of the system to reduce the complexity cut into small pieces by a function (self-oriented procedure that we usually top-down programming approach) .

  • Object-oriented programming and computer program as a collection of a set of objects, and each object may receive a message sent, other objects, and to process these messages, executing a computer program is a series of message passing between objects (the set of program packages together).

总的来说:面向对象是将事物高度抽象化,面向对象必须先建立抽象模型,之后直接使用模型就行了;面向过程是一种自顶向下的编程

Guess you like

Origin blog.csdn.net/ll148305879/article/details/94468068