Spring: slicing-oriented programming

Source: Internet
Author: User

Before we recorded spring's essays, it was a record of how spring injected the object, how to inject the property values of the object, that is, much of what we are talking about is one of the core concepts of spring-dependency injection (or control rollover, IOC), So, after learning from the "Common design Patterns: Proxy mode" that we learned a few days ago, let's learn about another core concept of spring, which is closely related to proxy mode, or a powerful application of proxy mode-oriented to slicing programming, that is, AOP (Aspect orientedprogramming)

First of all we know that Java is a classic object-oriented programming language (Oop,object orientedprogramming) object-oriented programming language has three major features, encapsulation, inheritance, and polymorphism, where inheritance allows us to define relationships from top to bottom, That is, subclasses can inherit some of the function functions of the parent class, or they can override some function functions of the parent class, but OOP is weak to introduce a common behavior for scattered objects (that is, objects other than the same parent class, where the parent class does not include object). It needs to add this common behavior in each object, so that the code is very repetitive, very redundant, the most typical is to add the log function, this log function and the core function of the object has nothing to do, but to add the log function for scattered objects, you have to open each of the scattered encapsulated objects, Then add the log function code, and we'll take this walk around the object core function-independent code, called the crosscutting code. To solve this problem, AOP emerges.

AOP is to encapsulate the common behavior of multiple classes into a reusable module (as we said in the last section of the log function) and name it "Aspect", that is, those that are not related to the core business of the class, but for the logical processing of the public invocation of the business module, can reduce the system duplication of code, Reduces coupling between modules and facilitates future operability and maintainability. AOP compensates for the lack of OOP's operation on the horizontal relationship. One of the two main ways to implement AOP technology is the dynamic proxy technology referred to in our common design pattern: proxy mode; there is also a way to introduce a specific syntax to create "facets" in a static weave, allowing the compiler to weave code about "aspects" during compilation.

The implementation principle of AOP in spring is the dynamic agent technology we mentioned earlier (if the principle is not very understanding, you can turn to the "Common design mode: Proxy mode"). So let's take a look at how to use the spring-oriented slicing programming to implement some of the features, first of all, let's look at some of the often-designed concepts in the spring-oriented tiling program:

Spring: slicing-oriented programming

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.