IOS learning 3: Extended Oop, category, and memory management of objective-C

Source: Internet
Author: User
Tags what inheritance

In fact, I don't know how to write these concepts. I can't copy them directly from a book. It's better to buy books.

Abstract concepts are generally written by masters. For example, this can be the Java programming idea of a pillow. That's really an idea. Once again, it is absolutely like reading a novel.

Abstract things have no good definition, because they cannot be defined.

The real understanding may still require our own time and accumulation.

Now I am studying iOS in my spare time for a week. At present, the grapefruit is just watching and practicing the part related to the selector.

Although I take notes, my notes only contain a few keywords.

Several days of code example practice, because sdk5.1 + xcode4.3.2 in the current development environment, regardless of the project file structure distributed in xcode, NIB, storyboarder, and arc mechanisms, the changes are quite large.

It is based on the OC base.

I. Concepts of OOP, object-oriented, should be available to all.

What inheritance, encapsulation, and polymorphism are the same as carrying words. However, it is easy to say in the vernacular.

Encapsulation: encapsulation I think is actually the most primitive foundation of OOP ideas. The object concept can be derived only after the introduction of encapsulation. We can better package an object and its attributes. It is a process of separation and integration.

Inheritance: inheritance is a good understanding of the literal sentence, and the son inherits the father. An object derives from a new object. Of course, you can endorse many of the inherited features.

Polymorphism: polymorphism is actually a better explanation. What are the forms of polymorphism? Multiple implementations of one thing (of course, this may be very intuitive and literal, but it is wrong from the rigor perspective)

It seems like inheritance. For example, if I have a fish, I can derive a shark class and a whale class. In this case, I feel like inheritance. In fact, their essential ideas are similar,

But the focus is different. Inheritance is more like expressing an object to derive a new object. polymorphism means that an object is derived from multiple objects and different implementations of the modified object, the most direct way to achieve this is to overwrite and implement different methods in the superclass. For example, fish have an eat () method. We all know that sharks eat meat, so we can implement the Eat method of sharks to eat meat. We can count on the blue whale, then, the Eat method of the blue whale is to implement the miscellaneous food method. Now you can simply see the concept of polymorphism from a comprehensive perspective.

A deep understanding of the concept of OOP is actually similar to the height of your treatment of abstract things.

2. New things or a centralized method of new classes.

1. the most primitive is that we abstract and define a class ourselves. For example, to define the most primitive class, such an original class object exists in Java and OC.

2. A new class is derived from the inheritance. This is easy to understand. For example, a man is derived from a human,

3. There is also a kind of method that we are less aware of, but is actually very often used: composite, both using a few different classes to compose a new class. The most common example is the car type,

We can use the engine and the tires wheel to construct the simplest car model.

Iii. Concepts of classes and informal protocols in oC

1. Category: category is a term exclusive to OC. category is defined in the book as a way to add new methods to existing classes.

In fact, how can this method be implemented like creating a subclass.

Yes. The most common way to extend a class is to create a subclass for it and add new methods to be extended.

However, it is sometimes inconvenient in OC. Here is an nsstring example. The original statement is as follows:

/**********

When you want to add a new behavior to a new class, we usually create a subclass.

But sometimes subclass is not convenient. For example, you may want to add some new behaviors to the nsstring class, but you know that nsstring is actually a foreground representation of a class cluster, so it cannot

Create a subclass for such a class. 1000 words are omitted.

********/

Well, we basically know from the above that the method for creating subclass has limitations, right. The above introduces a concept called a class cluster.

(A cluster of flowers is a bunch of flowers, which we don't know .)

In fact, class clusters are not a small concept. Collective can see Official Documents http://www.apple.com.cn/developer/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_9.html

The monks are also new to this stuff. There is such a sentence:

/*****

A class cluster combines some private and specific sub-classes under a public and abstract superclass.

****/

I don't know if I can understand it. The components of a class cluster are private, but we all know that the inherited sub-classes cannot access the Private Members of the parent class (should this be true ?)

Then the new method we add in the new subclass has no permission to access those things.

Well, the above is my personal understanding. This is what we hear. For details, refer to more official documents.

Well, we generally know the reason why OC introduces the category mechanism. With the allocation mechanism during the dynamic running of OC, you can add new methods for existing classes. Hey, this

Sounds cool! (Original words in the book)

CATEGORY creation:

@ Interface nsstring (numberconvenience)
-(Nsnumber *) lengthasnumber;
@ End // numberconvenience
The statement has two features:
(1) The existing class is located behind the @ interface keyword, followed by the class name in parentheses. The category name is numberconvenience, and this category will be added to the nsstring class. In other words, "we add a class named numberconvenience to the nsstring class ." Categories with the same name are unique, but you can add any number of different names.
(2) You can execute the class and category name you want to add to it, and list the added methods.
You cannot add new instance variables. Category life does not contain instance variables.

The implementation of classes is basically the same as that of General classes.


Informal agreements and delegation: the concept of informal agreements is actually another expression of the category. "Here are some methods you may want to implement, and you can use them to better complete the work ".

This means that these are optional. For example, if we want a better method, we will declare such a category to implement it. Then you can directly use these better methods later.

In this case, we always think the category is a bit like an optional protocol.

The Optional Protocol is only a matter of foresight, and the category is a later remedy. When we work together, the method implementation is optional. The Optional Protocol has a key optionnal statement, And you declare the type as you do in an efficient way,

If you don't want.

Afterwards, it was commissioned to calculate a very important concept in OC. It is said that many things will be found in depth, and the main people are still only engaged for a few days, but still do not know much about the overall design pattern theory in OC.

When writing the sample code, how does one feel like listening and callback in Java. It may be necessary to have a better understanding, but it is still necessary to have more contact with the code to have a deep understanding.


Iv. Changes in memory management

Therefore, the change in memory management is the most important issue in the work of C and C ++ members.

Before getting started with ios5.1, I read most of the information on the Internet, and the memory management is very important.

However, when I learned, I found that this piece was deprecated.

The new features of the current version introduce the arc mechanism. I Feel Like java.

After creating the arc option for a project, you will find that you do not need to manually release the memory in the code. Release has been crossed out =.

I don't know whether this is a good thing or a bad thing. Maybe for new users, wow .. It is much easier.


Complete

------- Sort notes on March 22




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.