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).