1. What is tangent-oriented programming
In software development, the functions scattered in the application are called crosscutting concerns, which are conceptually separate from the business logic of the application, but often are embedded directly into the business logic of the application, separating these crosscutting concerns from the business logic to solve the problem of formal aspect-oriented (AOP). DI facilitates decoupling between objects, and AOP enables decoupling between crosscutting concerns and the objects they affect.
For example, security is a crosscutting concern, and many of the methods in the application involve security rules, and if you want to reuse common functionality, common object-oriented techniques are inheritance or delegation, but inheritance often leads to a fragile object architecture, and using delegates may require complex calls to delegate objects. Facets provide an alternative to using aspect-oriented programming, where we still define common functionality in one place, but declaratively define how the feature is to be applied, without modifying the affected classes. Crosscutting concerns can be modularized into special classes, which are called facets (aspect). There are two benefits to this, with each focus being focused on one place instead of being scattered across multiple codes, followed by application-only business logic code, and security, transaction management, etc. are transferred to the slice.
The terminology commonly used in AOP has notifications (advice), pointcuts (pointcut), and connection points (Joinpoint). The work of a slice is called a notification that describes the work to be done and when to do it, and the spring facets can apply 5 types of notifications:
- Pre-notification (before): invokes the notification function before the target method is called
- Post notification (after): Notifies when the target method is complete and does not care what the output of the method is
- return notification (after-returning): Call notification after successful execution of the target method
- Exception Notification (after-throwing): Call notification when the target method throws an exception
- Surround Notification (Around): Notifies the method that the notification has been wrapped, and performs custom behavior before the method call is notified and after the call
The time to apply a notification is called a connection point, which is a point at which a slice can be inserted during application execution, when the method is called, when an exception is thrown, or even when a field is modified.
The pointcut defines where to apply the notification, the definition of the pointcut matches a point or multiple connection points to which the notification is to be woven, we typically specify these pointcuts with explicit class and method names or with the class and method names that are matched by regular expression definitions, and some AOP frameworks allow for the creation of dynamic pointcuts, You can decide whether to apply notifications based on the decision of the runtime.
Facets are the combination of a notification and a tangent point, which together define the entire contents of a slice, what it is, and when and where it accomplishes its function.
Introduction (Introduction) allows us to add new methods or properties to an existing class, and we can create a notification class that records the state of the last modification of an object through an instance variable and setter method. The new method and instance variables can then be introduced into existing classes, allowing them to have new behaviors and states without modifying the current class.
Weaving is the process of applying facets to a target object and creating a new proxy object. Facets are woven into the target object at the specified connection point and can be woven at multiple points in the life cycle of the target object: Compile time, class load period, run time, and Spring AOP is woven into the application runtime.
Springinaction Reading Notes--The 4th chapter faces the Facets