The difference between process programming and object-oriented programming __UML

Source: Internet
Author: User
process-oriented programming

Process-oriented programming is a process-centric programming idea, analyzing the steps to solve the problem, and then using the function to implement these steps step by step. Process-oriented programming, data and the operation of the data is separate. Object-oriented programming for object-oriented programming is to solve the problem through object communication. Object-oriented programming, data and operations on the data are bound together.

Three basic features of object-oriented:

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

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

Polymorphism: Many different implementations of interfaces are polymorphic. The same operation works on different objects, producing different execution results. At run time, a virtual function in a derived class is invoked by pointing to a pointer or reference to a base class to implement polymorphism.

Encapsulation can hide implementation details, making code modular; Inheritance can extend existing classes. They are designed to---code reuse.

Polymorphism is---interface reuse in order to achieve another goal.

Object-oriented code supports reuse, reduces the cost of software development and maintenance, and improves the quality of software.


The difficulty in mastering object-oriented is the transformation of ideas. Instead of thinking about abstracting the problem as an object, we usually get used to thinking about how to solve the problem.

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:
To take a car as an object, to extract the generality of all vehicle objects, to design a class car, to have a method void drive () in the class, to instantiate a specific object car with this class, called: Car.drive ().


A second simple example: find the circumference and area of a rectangle.
Process-oriented programming approach:
1, determine the rectangle circumference and area of the algorithm.
2. Write two methods (functions) to calculate the circumference and area of the rectangle respectively.
3, the method of finding circumference (function) and the method (function) of the area need two parameters, respectively, is the length and width of the rectangle.

Object-Oriented Programming approach:
1, a rectangle can be seen as a rectangular object.
2, a rectangular object has two states (long and wide) and two behavior (seek Zhou Changhe area).
3, the generality of all the rectangles extracted out, design a rectangular class.
4, through the behavior of rectangular objects, you can find a specific rectangular object's circumference and area.



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.