The first exposure to OC polymorphism, dynamic types and dynamic binding

Source: Internet
Author: User

Polymorphism: different classes are allowed to define the same method.

Dynamic type: the class to which the program belongs cannot be determined until it is executed.

Dynamic binding: The program cannot determine the method to be called until it is executed.

ID: A Common Object type. That is, ID can be used to store objects belonging to any class, so that the output of different classes does not need to be specified. It is better to use an ID type.

Polymorphism occurs in order to allow different classes to use the same method. For example, add, which greatly improves the readability of the program and reduces the programming difficulty. Add is +, and the type of + is marked with ADD, which is clear and easy to understand.

Dynamic type and dynamic binding are designed to solve the drawbacks caused by the convenience of polymorphism. with dynamic type and dynamic binding, you do not need to consider the type of add in the output, it is automatically determined.

The ID type is used to better accept the return values of dynamic types and dynamic methods. So that there is only one sum corresponding to add, and only sum needs to be output during output, and sum does not need to be customized in each class.

 

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.