6.ios-Management and classification of the type of storage

Source: Internet
Author: User

Knowledge points
1. Automatic release of the pool
2. Inheritance and polymorphism

========================
Auto Free Pool
1. What is the automatic release pool
2. Automatic release of the function of the pool
1) Thinking: How to release objects that need to be returned in a function
3. How to create an auto-release pool
@autoreleasepool {} After---IOS5.0
4. Auto-release pool How to free object memory
1) autorelease Message
Function: Indicates the delay will be released again, to the object to play a autorelease
Indicates that the object is joined to a recent auto-release pool.
When the auto-free pool is destroyed, all
Object to do the release operation once
5. Stack-structured management of the automatic release pool
6.autoreleasepool principle
The auto-free pool saves all objects in the pool in an array,
When the release pool is destroyed, a release operation is made for all objects in the array

========================
Inheritance and polymorphism
1. What is inheritance
Inheritance is the technique of building a new class using the definition of an existing class,
The definition of a new class can add new data or new functionality, or you can use the functionality of the parent class
2. The role of inheritance
1) Create a new type with an existing type
2) Fast and convenient extension code
3. Ways of inheriting
4. Hierarchy of inheritance
1) What is a parent class (superclass, base class) and subclass (derived class)
2) Parent-Child inheritance relationship
5. Inheritance of messages for fields
1) Three ways to access member variables in OC
@public: Can be accessed by all functions and can be inherited by the quilt class
@protected: cannot be accessed by an external function, and can be inherited by a quilt class
@private: cannot be accessed by an external function and cannot be inherited by a quilt class
2) Inheritance of messages
All functions (Messages) in OC are public, meaning that all messages can be inherited by the quilt class.
6. Rewrite
1) What is rewriting
2) Role of rewriting
Extending the functionality of the parent class
3) call to rewrite message
1>OC messages are virtual functions.
function calls in OC are determined at run time.
2>self and Super
4) Overriding the NSObject base class
Init message
Description message
Dealloc message

7. Overloading
1) What is overload
There is no strict overload in OC
Because OC distinguishes different functions by function name
2) Effects of overloading
Print

3) Overloads in OC
No overloads exist in OC

8. Inheritance Relationship
1) function analysis, sub-class function >= function of base class
2) analysis from the inheritance relationship, base class > Subclass Long int
3) based on the 2nd, you can refer to the object of the child class with a pointer to the parent class,
This behavior is called an upward-type conversion, which is an implicit conversion, which instead requires a forced type conversion

==========================
Polymorphic
Conditions: inheritance, overriding parent class, virtual function

1. What is polymorphic
1) The object responds differently depending on the message
2) Function: Improve the reusability of the program, extensible and can be used for maintainability
2. How to Implement Polymorphism
1) must inherit
2) referencing subclasses by parent class
3. Function invocation principles for parent-child classes
4. Whether different pointers can invoke all functions in the object
1) When a parent class references a subclass object, it can access only the methods common to the parent and child classes
2) Think: Can I refer to the parent class object by subclasses
3) Thinking: How to invoke a method in a subclass
Which functions can be called by the 5.id type variable
1) The object that the ID type refers to, that is, you can call a method in a subclass, or you can call a method in the parent class

=========================
Categories (category)
1. What is classification
Classification is a compile-time tool that allows us to augment a class by adding a method to it
(But you can't add new instance variables by category), and we don't need to access the code in the class
2. Role
1) You can create a new method for a class without having to edit the class definition in code
2) by category, you can spread the implementation of the class into different files
3. How to create a category
4. Use of categories
1) contains the category header file
5. Areas to be aware of in the category
1) Unable to add new instance variable to class, class has no location to hold instance variable
2) access to all members and methods in the class
3) name conflict, that is, when a method in a category conflicts with the original class method name,
The category has a higher priority. The class method will completely replace the initial method so that the initial method can no longer be used, so this is not recommended
6. Priority of method invocation:
1) Category > Original class > Parent class
2) If the same method is implemented in multiple category, only the last one participating in the compilation will be valid.

Extension (Extension)
1. What is an extension
Extensions are anonymous categories
2. Differences in classification and expansion
1) Adding new attributes is not allowed in the classification
2) extension allows new properties to be added


//
After-school assignments:
1. There are two classes of rectangles and squares, member variables have width width, height height, area, perimeter, create these two classes in as simple a way as possible

2. Design two classes on pets
Cat properties: Height, Weight method: Run, jump, wash face
Dog properties: Height, Weight method: Run, jump, wag tail
Create these two classes in as simple a way as possible

3. The kindergarten lost the candy, the teacher asked the little boy and the little girl:
The little boy said, "Not me."
The little girl said: it's him.
Write a program that simulates the process above
4.
There are three kinds of cars, trucks, trucks, buses, the speed is 60, 40,30
There are three kinds of road, highway, Country Road, Mountain Road, Speed 0,-10 respectively,-20
S T
Ask any car, through any long road, how much time

6.ios-Management and classification of the type of storage

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.