Object-oriented language features: encapsulation, inheritance, polymorphism

Source: Internet
Author: User

1. The characteristics of object-oriented languages mainly include:
Encapsulation: Hiding internal implementations
Inheritance: Reusing existing code
Polymorphism: Overriding object behavior


1.1 Package
Encapsulation is an information concealment technique, which is embodied in the description of the class and is an important feature of the object. Encapsulation makes the data and the method (function) of processing the data encapsulated as a whole, in order to achieve a very independent module, so that the user can only see the external characteristics of the object (the object can accept which messages, with those processing power), and the object's internal characteristics (the preservation of the internal state of private data and the implementation of processing capacity algorithm) is The purpose of encapsulation is to separate the use of the object's designer from the object, and the user does not have to know the details of the implementation of the behavior, but only accesses the object with the information provided by the designer.

1.2 Inheritance
Inheritance is the mechanism by which subclasses automatically share data and methods between parent classes. It is represented by the derivation function of the class. A class inherits all the descriptions of other classes directly, and can be modified and expanded. Inheritance has transitivity. Inheritance is divided into single inheritance (a subclass with only one parent) and multiple inheritance (a class has more than one parent class, and the current Rt-thread object system cannot support it). The objects of the class are closed, and if there is no inheritance mechanism, the data and methods in the class object will be duplicated a lot. Inheritance not only supports the reusability of systems, but also facilitates the extensibility of the system.

1.3 polymorphic
The object is acting according to the received message. When the same message is accepted for different objects, it can produce completely different actions, known as polymorphism. The use of polymorphic users can send a common message, and all implementation details are left to the object receiving the message, so the same message can invoke different methods. The implementation of polymorphism is supported by inheritance, with the hierarchical relationship of class inheritance, the protocol with common function is stored at the highest level of class, and the different methods of implementing this function are placed at a lower level, so that the objects generated at these low levels can respond differently to generic messages.

Object-oriented language features: encapsulation, inheritance, polymorphism

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.