Object-oriented (POP), process-oriented (OOP), and popoop

Source: Internet
Author: User

Object-oriented (POP), process-oriented (OOP), and popoop

My understanding of object-oriented and process-oriented

  • Process-oriented: (procedure oriented programming: POP)

Process-oriented is to analyze the steps required to solve the problem, and then use functions to implement these steps Step by step. You can call these steps one by one.

In the early days, low computer configuration and low memory size, process-oriented programming (time-for-space) were mostly adopted to save memory space ).

  • Object-oriented :( object oriented programming: OOP)

Object-oriented is a programming paradigm that satisfies the needs of object-oriented programming languages. Generally, classes, encapsulation, inheritance, and other syntaxes and concepts are provided to assist us in object-oriented programming.

The so-called object-oriented approach is to modularize and target our programs, and put the characteristic attributes of specific things and the specific methods for implementing some actions through these attributes into a class.

2. Three features of object-oriented: inheritance, encapsulation, and Polymorphism

(1) Inheritance

Inheritance: Class A inherits class B. We generally call the inherited Class A as A subclass and the inherited Class B as A parent class;

Understanding: Child classes have a special and general relationship with parent classes. Child classes are more detailed categories of parent classes.

After inheritance is implemented, the subclass automatically owns the attributes and methods of the parent class. The subclass can write its own attributes and methods to implement function extension, sub-classes can also rewrite the methods of the parent class, that is, method rewriting.

(2) Encapsulation

  • Encapsulation refers to placing data and specific operation implementation code inside an object so that the implementation details of the Code are not discovered by the outside world. The outside world can only use this object through interfaces,

The internal implementation of an object cannot be modified in any form. It is precisely because of the encapsulation mechanism that the program does not need to care about the data structure details and implementation operations of an object when using an object.

That is to say, you do not need to know the implementation details of the object's internal methods, but you can access the object based on the external interfaces (object names and parameters) provided by the object.

  • Advantages of encapsulation:

Encapsulation can hide the Implementation Details of objects to make the code easier to maintain. At the same time, because private information inside objects cannot be directly called or modified, the system security is guaranteed to some extent.

1. A professional division of labor is achieved. After the code that can implement a specific function is encapsulated into an independent entity, Each programmer can call it as needed, thus achieving a professional division of labor.

2. Hide information and implement details. By controlling access permissions, you can hide information that you do not want the client programmer to see. For example, if the password of a customer's bank needs to be kept confidential, you can only develop permissions for the customer.

(3) polymorphism

Polymorphism is another prominent feature in object-oriented programming. The so-called polymorphism refers to that in the inheritance system, all derived classes inherit interfaces from the base class, but since each derived class is an independent entity, therefore, when receiving the same message, different responses may be generated. The role of polymorphism is to hide the code implementation details, so that the code can be modularized; the Code module can be extended to achieve interface reuse. Simply put, an action produces multiple effects.

In general, encapsulation can hide Implementation Details and contain private members, modularize the code and add security indexes. inheritance can expand existing modules for code reuse; polymorphism is used to ensure that when the class is inherited and derived, the instance of any class in the family tree is called correctly, and the interface is reused.

 

Related Article

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.