Understanding of AOP, AOP
AOP: Aspect-Oriented Programming. You can see a good understanding and a good example of AOP when watching the video.
Optimal example: Permission control.
In permission control, the original method (not the original method I will not) is to determine the permissions of a person in each place where permissions need to be controlled through if, then, grant or not grant a certain permission. For example:
In this process, once authorization is required for every button, page, or other element, such a judgment is required. The process of this judgment is obviously code duplication. Therefore, it is necessary to separate the if judgment. We only need to focus on the do xxx part.
The process of separating if judgment is an embodiment of AOP.
Java extracts AOP Using the proxy method. Simply put, it is to set a proxy object to intercept all business methods, and then determine whether the user has the access permission. if the user has the permission, the service method can be executed, otherwise, the execution of business methods is not allowed.
That is, assign all business implementation methods of the target object to the proxy object. In this way, you only need to perform operations on the proxy object, rather than redundant code on the target object.