Item02. Polymorphism PolyMorphism

xiaoxiao2021-03-05  22

Item02. Polymorphism

-------------------------- Polymorphic Type: Have a virtual function class Type (Class Type) Polymorphic Object: Objects with multiple Type Polymorphic Base Class: Base class for Polymorphic Object

-------------------------- 1, Polymorphic Type inherits from the parent class is the interface instead of achieving 2, a design correct Polymorphic Class must be able to replace each of its base classes. (Up Type Conversion) 3, the Polymorphic Base Class can be regarded as a contract, providing the user with an interface (eg, virtual function), and the specific subclass is responsible for implementing the interface. 4. The interface of the subclass can be called by 2, 3, that is, the statically type of the object is the parent class, and the dynamic type is its subclass. 5, the relationship between the parent class and the subclass: The parent class does not know what to do, the subclasses only need to care about the interface of the parent class it needs to be implemented.

转载请注明原文地址:https://www.9cbs.com/read-38292.html

New Post(0)