Springinaction Reading Notes--The 4th chapter faces the Facets

Source: Internet
Author: User

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

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.