IOS stage study 13th days notes (polymorphism), ios 13th days

Source: Internet
Author: User

IOS stage study 13th days notes (polymorphism), ios 13th days

Knowledge points of IOS Learning (oc language)

I. Polymorphism

1) popular understanding of polymorphism, that is, multiple forms of a method.

2) compatibility with polymorphism assignment: that is, the reference of the parent class can point to the object of the subclass.

3) when calling a method in polymorphism, you can view the object instead of the pointer. That is, you can view the method to be executed and the object instance to call this method.

4) the reference of the parent class cannot call the methods and attributes unique to the subclass, and must be converted to a subclass.

5) use of the combination class (that is, the class contains other class objects). Note that when using the combination class, we need to override the initialization method of the system and instantiate the class objects in the combination class, in this way, later member methods can directly operate on member objects.

6) in polymorphism, we can use @ class to add references to the class (the members in the class are unclear). This prevents header files from being contained in each other.

7) in polymorphism, we can use isMemberOfClass to determine which class object the current instance belongs. For example:

1-(void) beaten :( Animal *) animal 2 {3 // Animal is the parent class (Animal has multiple classes such as Dog, Cat ....) cat is a subclass of 4 if ([animal isMemberOfClass: [Cat class]) {5 6 NSLog (@ "cat"); 7 8} 9 [animal action]; 10}

 

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.