The dynamic characteristics of the language of the shallow thinking OC

Source: Internet
Author: User

It's been a while since I've been learning about iOS for the language of shallow thinking oc. Today took a little time to think about the language characteristics of OC, let their heart not so impetuous, pay attention to the foundation, return to the source.

OC as an object-oriented language, nature has object-oriented language characteristics, such as encapsulation, inheritance, polymorphism. He has the characteristics of static language (such as C + +), but also the efficiency of dynamic language (dynamic binding, dynamic loading, etc.). On the whole, it is really a good programming language.

Now, let me think about the dynamic language characteristics of OC. The dynamic characteristics of OC are expressed in three aspects: dynamic type, dynamic binding, dynamic loading. It is called dynamic because it has to be run time to do something.

(1) Dynamic type

Dynamic type, say the simple point is the ID type. Dynamic types are relative to static types. Clear basic types like built-in are all static types (int, nsstring, etc.). Static types can be identified at compile time. Therefore, if the program does not correspond to the type, the compiler will issue a warning. Dynamic types are not recognized when compiled by compilers, and are not recognized by context until the runtime (run time) is run. So here are two concepts to distinguish: compile-time and run-time.

(2) Dynamic binding

Dynamic binding is hard to remember, but in fact it's simple, just memorize the keyword @selector/sel. First look at "functions", for some other static languages, such as C + +, generally at compile time will be called the function of the function of the signature to tell the compiler. Static, cannot change. In OC, in fact, there is no concept of function, we call "message mechanism", the so-called function call is to send a message to the object. At this point, the dynamic binding feature is coming. OC can skip the compilation, until the runtime to dynamically add function calls, at run time to decide what method to call, what parameters need to pass in. This is dynamic binding, and to implement it, you must bind a method with the SEL variable. The resulting SEL variable represents a reference to a method. Note here: The SEL is not a function pointer in C, although it is similar, but really not a function pointer. The SEL variable is just an integer, and he is the ID of the method. The previous function call, which is based on the function name, is the string to find the function body. But now, we're looking for methods based on an ID integer, and the search word for integers is naturally much faster than searching for strings. Therefore, the specific of dynamic binding is not only convenient, but also more efficient.

(3) Dynamic loading

such as the dynamic loading of pictures:

is to put the picture (or image path) in the database, where you want to show the picture, from the database to display pictures,
Because the database is updated at any time, the picture will be different, called dynamic is dynamically loading resources on demand.


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.