I. AOP example
1, Google Toolbar: Block pop-up windows, add links to Amazon for ISBN
The original HTML document knows nothing about Google Toolbar's hands and feet, and toolbar gets the original document and begins to weave the code into it based on a specific matching condition:
If you have code that calls a pop-up window, insert a comment around the code
If there is an ISBN number, insert a link for this text <a href= "Http://www.amazon.com/isbn=xxxx" >
The final display in the browser, will be less pop-up window code, more than the ISBN link 2, ctor/dtor
In fact, the traditional support object-oriented language has unconsciously included the idea of what is now called AOP, which is the constructor and destructor: The compiler automatically inserts code when object creation and object destruction, where aspect is "the time to automatically manage resource acquisition and release for objects"; This idea expands, For example, if you insert code when entering or exiting a particular function, it is AOP II. Example of the IOC elevator
Even though I had already started to get higher education, I still made mistakes when I used the elevators a couple of times: when I wanted to go down to the first floor on the upper floor and when the elevator was on the lower floor, my first reflection was to let the elevator come up to me, so I pressed the "up" button and the elevator didn't start down as I hoped But to continue upward; and then I was in the hospital, and I observed a lot of the families of the patients who came from the countryside without contacting the elevators, and constantly making the same mistakes.
In fact, the use of elevators is simple: when you want to press the "next", when you want to press "up", you can, when you want to "control" the elevator, things become troublesome
So the idea of the elevator and the IOC is the same: Speak your needs, the control behind the system.