Dependency Injection and AOP Brief (13)--AOP Application Example (end).

Source: Internet
Author: User

2. Examples of AOP applications

In general application development, there are some typical AOP applications that allow developers to focus on the business logic itself rather than some "facets" that are not completely unrelated to it.

The first is about the previous description of the function of the log output class, of course, the previous example is very simple, in fact, the output of the log information often has a lot of variable parameters, then need to be intercepted from the context of the object to remove the corresponding information to enhance the behavior.

The most common AOP application is the management of DB transactions. The business process succeeds in committing the transaction to the DB, whereas the transaction is rolled back-this is the code that every developer will write. In practice, however, the processing of such transactions is completely independent of the "aspect", which does not depend on any logical implementations, i.e. any logical processing of the DB is committed or rolled back, so the functionality of the DB transaction management is often managed by the AOP framework. Spring, Seam, and Guice include the functionality of container management transactions in EJB applications, which are essentially AOP applications.

In addition, the function of security processing is often related to the logic developed by the developer "aspect", because all need to determine whether the current user has permission to execute a certain logic such a requirement, is generally the same processing method-the user has permission to continue processing, the user does not have permission to throw an exception. In this case, in order to avoid developers to write a large number of if statements, the framework provided by the AOP approach to make security decisions should be the best solution.

The topic of dependency injection design pattern is actually a very broad topic, different frameworks have common or different ideas, the best practices produced also have similar side and different side, we here because space is limited, can only do the above superficial introduction, If you are interested, you can continue to explore this very successful design pattern through the Internet and various books.

Dependency Injection and AOP Brief (13)--AOP Application Example (end).

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.