OC Basic principles of exploration document summary
What is a callback function? Normally we call functions of other classes or libraries directly, but sometimes we need to write A method A to pass to function B of another class or library, so that function A will execute when function B executes. This function A is the callback function. B is the intermediate function. Function A passed to function B is called the registration callback function. When function B calls function A at run time, it is called A callback function.
For example:
Things: a hotel provides wake-up service, but the guests are required to decide their own wake-up method, different passengers have different wake-up methods, the guests tell the hotel in advance of the wake-up method, to a certain time after the hotel will use the corresponding wake-up service.
To understand:
- The wake-up call is the intermediate function
- The wake-up call is the callback function
- The process of registering back to the function is that the guest tells the hotel the wake-up method in advance
- When the hotel performs the wake-up service provided by the guest, it makes a callback
Essence: Dynamic registration function
Advantages: Great flexibility, functions passed as parameters can be registered dynamically
Why is it called a callback? System programming is divided into two types, the system layer and the application layer. In general, the application layer directly calls the function of the system layer, but some functions can be passed in a function for the application layer to improve flexibility, and the function passed in is the callback function. That is, the word callback does not come from an intermediate function calling the original function, nor from the class calling the original function, but from the system layer calling the application layer function back