OC Section nineth class Extension

Source: Internet
Author: User

1. Category Category

①. class is to add a method to a class inside the system or to a class that does not have source code, and cannot add an instance variable

② . The added method is referred to as part of the original class, and subclasses can still use the

  ③. class Destination file name is original + file name (for example: Nsstring+wuyaun)

  ④. you can either add an instance method or add a class method

2, Extension extension

①. extensions are for custom classes that extend the functionality of the

②. above the . M file, build the extension using the @interface keyword

③.   in the extension, we can either declare a method or declare an instance variable or property

④.   the added content belongs to the private part of this class.

3, delegate agreement, agent execution.

@class A; // tell compiler a is just a class name, as to what instance variables, properties, methods are not known in the class

4. polymorphic Applications

//Polymorphic , is a variety of forms, There are many states there must be inheritance

//The nature of polymorphism is that the parent pointer points to the child class object

//polymorphic use, the system dynamically monitors what type the pointer is pointing to, althoughcar is a car * type pointer, but when car executes the method alone, TA is the Benz object

// parent pointer as a function or a parameter to a method, when executing a method or invoking a function, passing in a specific subclass object, you can execute methods such as.

Polymorphic Disadvantage, the parent pointer must be able to execute a subclass of methods, can only perform inherited methods, if you want to use, you have to do a strong turn.

OC Section nineth class Extension

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.