I. AOP Example 1: Google Toolbar: intercept the pop-up window and add a link to Amazon to ISBN
The original HTML document knows nothing about Google Toolbar. After the toolbar obtains the original document, it is woven into it according to specific matching conditions.Code:
If there is code that calls the pop-up window, insert comments around the code
If there is an ISBN number in it, insert a link for this text, such as <a href = "http://www.amazon.com/isbn=xxxx">
In the browser, the pop-up window code and ISBN link are missing.
2, ctor/dtor
In fact, the traditional support for object-oriented languages has unconsciously included the idea currently called AOP, Which is constructor and destructor: the compiler automatically inserts code when the object is created and destroyed. The aspect here is "The time for Automatic Resource Acquisition and release of the Object Management". This idea is extended, for example, if you insert code when entering or exiting a specific function, it is AOP.
Ii. IOC example elevator
Even though I have already started higher education, I still make mistakes when using the elevator several times before: when I want to go down to the first floor on a higher floor while the elevator is on a lower floor, my first response was to let the elevator come up and take a good ride, so I pressed the "on" button. The result was that when I got into the elevator, the elevator did not start to go down as I expected, instead, I continued to go up. Later, I was in the hospital and observed that many families of patients from rural areas who had never been in touch with elevators were making the same mistakes.
In fact, the elevator is easy to use: when you want to get down, press "down", and when you want to get up, press "up; when you want to "control" the elevator on your own, things become troublesome.
Therefore, the idea of elevator and IOC is the same: Just say what you need, and the control behind it is done by the system.