C ++ three characteristics (inheritance, encapsulation, polymorphism)

 

 Package

Is the objective things packaged as an abstract class, and the class can put their data and methods allow only trusted class or object manipulation, hiding on untrusted information. A class is a logical entity that encapsulates data and operation code data. In an internal object, some code or some data may be private and can not be accessed outside world. In this manner, the internal data objects provide different levels of protection to prevent accidental changing part of the program irrelevant or incorrect use of the private portion of the object.

inherit

It refers to an object can make some type of method for obtaining the properties of an object of another type. It supports the concept of by-level classification. Inheritance refers to such a capability: it can use all the features of an existing class, and without having to rewrite these functions extend the case of the original class. Create a new class by inheriting called "sub-class" or "derived class", inherited class called "base class", "parent" or "superclass." Succession process, that is, from the general to the particular process. To achieve inheritance, it can "inherit" ( Inheritance) and "combination" ( to achieve Composition). Implementation of the concept of inheritance of three categories: implementation inheritance, interface inheritance and visual inheritance.

Inheritance: it refers to the ability to directly use the properties and methods of the base class without additional coding;

Interface Inheritance: it refers to the properties and methods using only the name, but the subclass must provide the ability to achieve.

Visual Inheritance: Inheritance refers to the visual appearance subform (s) using base form (s) and the capability of the code implemented.

Polymorphism

It refers to the same manner as a class instance can have different forms in different situations. Of polymorphism so that objects having different internal structures can share the same external interface. This means that, although different specific actions for different objects, but through a common class, they (those operations) can be invoked in the same way.

    Polymorphic C ++ virtual functions and virtual inheritance based on. In summary, C ++ polymorphism core, is to use a more universal base class pointer to a different subclass instance, in order to invoke the correct method, we need to use virtual functions and virtual inheritance. In memory, by the virtual function table to achieve the correct subclass method call; via virtual base pointer, retaining only memory structure of a base class, to avoid conflict.

    The so-called virtual, is to "direct" things change "indirect." Originally a member function static member function pointers defined, and the virtual function is a virtual function table to point to the real function pointer, so as to achieve at runtime, determined indirectly to achieve the desired function. Inheritance original base class is a direct copy of the memory space to achieve, and the virtual inheritance virtual base class with a pointer to the virtual base class, the base class to avoid duplication.

Reference links:

【1】https://www.cnblogs.com/BEN-LK/p/10720249.html

【2】https://blog.csdn.net/IOT_SHUN/article/details/79674293

【3】https://www.cnblogs.com/longjiang-uestc/p/9594561.html

Guess you like

Origin www.cnblogs.com/lalalatianlalu/p/11517625.html