iOS Stage Learning 13th day notes (polymorphic)

Source: Internet
Author: User

iOS Learning (OC language) Knowledge Point finishing

One, polymorphic

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

2) polymorphic assignment compatibility: That is, a reference to the parent class can point to the object of the child class.

3) When invoking a method in a polymorphic state, look at the object without looking at the pointer, that is, we want to see which method is executing to see which object instance we are calling this method.

4) A reference to a parent class cannot call a subclass-specific method and property and needs to be strongly turned into a subclass.

5) The use of combinatorial classes (that is, classes that contain other classes of objects), note that when using a composite class we override the initialization method of the system and instantiate the class object in the composition class so that the Member object can be manipulated directly by subsequent member methods.

6) In polymorphism we can use @class to add a reference to a class (a member in a class is not known): Prevent header files from being included with each other.

7) In polymorphism we can use Ismemberofclass to determine if the current instance is the object of that class. For example:

1-(void) Beaten: (Animal *) Animal2 { 3     //Animal is a parent class (animal has multiple classes such as dog, Cat ...). Cat is one of these subclasses4     if([Animal ismemberofclass: [Catclass]]){5 6NSLog (@"Cat");7 8     }9 [Animal action];Ten}

iOS Stage Learning 13th day notes (polymorphic)

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.