Simple to sum AOP and IOC

Source: Internet
Author: User
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.

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.