The difference between process-oriented programming and object-oriented programming

Source: Internet
Author: User

process-oriented programming

Process-oriented programming is a process-centric programming idea, which analyzes the steps to solve the problem, and then uses the function to carry out these steps in a step-by-step way. Process-oriented programming, the data and the operation of the data are separated.

Object-Oriented programmingObject-oriented programming is the object of things, through object communication to solve the problem . Object-oriented programming, data and manipulation of data are bound together.

Three basic features of object-oriented:

Encapsulation: to encapsulate objective things into abstract classes, to hide the implementation details of attributes and methods, and to expose interfaces only externally.

Inheritance: Subclasses can use all the functions of the parent class and extend these functions. The process of inheritance is from the general to the special process.

Polymorphism: Many different implementations of interfaces are polymorphic. The same action acts on different objects, producing different execution results. At run time, a virtual function in a derived class is called by a pointer or reference to the base class to achieve polymorphism.

Encapsulation can hide implementation details and make code modular; inheritance can extend a class that already exists. They are designed to---code reuse.

Polymorphism is---interface reuse for another purpose.

Object-oriented code more support reuse, can reduce the cost of software development and maintenance, improve the quality of software.


The difficulty in mastering object-oriented is the transformation of ideas. We are often used to thinking about solving problems rather than thinking about abstracting them into objects and solving them.

From two simple examples to understand the difference between the two


The first simple example: write a way to drive a car

Process-oriented Programming:
Write a method, void Drivecar ();
Object-Oriented Programming:
Consider a car as an object, to extract the generality of all car objects, to design a class car, the class has a method void drive (), with the class of car instantiation of a specific object car, called: car.drive ().


A second simple example: Ask for a rectangle's circumference and area.
Process-oriented programming approach:
1, determine the rectangular circumference and area of the algorithm.
2, write two methods (functions) calculate the circumference and area of the rectangle respectively.
3, the method of the circumference (function) and the method of finding the area (function) requires two parameters, respectively, the length and width of the rectangle.

Object-Oriented Programming methods:
1, a rectangle can be regarded as a rectangular object.
2. A Rectangle object has two states (length and width) and two behaviors (seeking circumference and for area).
3. Draw out the generality of all rectangles and design a rectangular class.
4, through the behavior of the rectangular object, you can find a specific rectangle object circumference and area.



The difference between process-oriented programming and object-oriented programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.