Chapter 5 Aspect-oriented programming (AOP)

Source: Internet
Author: User

You may already be familiar with object-oriented programming. Currently, object-oriented technology is very popular. It has been recognized by many developers. Compared with the previous process-oriented, it is simply a qualitative leap. Now that we have an object-oriented programming model, why do we have to look at this idea?

Object-Oriented programming focuses mainly on core services, while Aspect-oriented programming focuses mainly on services that are not the core, but also necessary auxiliary functions. For example, in a complete system, to record the exceptions thrown during system operation, we need to record them so that we can fix them as soon as possible. This is a common log. Transactions are indispensable for some data operations that require important requirements, such as financial systems. Such data is very important and every step of operation is very important. We should use transactions. This is our common transaction processing. You can select applications based on the importance of your system data. Security authentication is also commonly used. For different pages, the access identity is also different. This is our common authentication. For some pages or modules in our system with a relatively large access volume, we can use the cache mechanism to deal with these frequently accessed pages to make up for performance failures, to ensure the performance is not affected, the cache mechanism is required. These are not specific to the specific business module, but may be specific to all modules. They are only some additional functions, relative to the main functions of the module. If these codes are included in each module and are not the core business code, they seem to be related to the core business. However, such processing will be a headache for future maintenance. At the same time, it violates an object-oriented principle and is responsible for itself. Services that do not belong to this method are also included. This kind of code is not only difficult to maintain, but also difficult to reuse and has a large Coupling Degree. Cohesion is also relatively low. Such code may not cause any trouble, but it may cause trouble for later maintenance personnel.

Aspect-Oriented Programming is mainly used to assist core businesses. It is not a core business, but it is indispensable. In this way, we can understand its combined use with object-oriented thinking. In fact, Aspect-Oriented Programming is to extract and modularize the codes mixed in the core business methods, and regard them as a module function separately to accomplish more perfect functions together with the core business.

The Aspect-oriented programming (Aspect-Oriented Programming, AOP) has appeared very early. It is used in conjunction with spring's IOC, and reflects the powerful functions of AOP. before talking about how it works with spring, let's talk about several difficult and difficult concepts. why does it not name some concepts that are easy to understand? Some people have named them for a long time, so the AOP mentioned in spring is no exception. in JBoss, aspectj... all have the concept of AOP. the concepts are the same. see how you understand and use it. let's briefly discuss several common concepts.

First: aspect. This is a Chinese translation. You can translate it into aspect, part... there are too many translations for it, so we don't pay attention to this. We know that it is the core function. A simple understanding of the aspect is to extract the code that is not the core business should process and encapsulate it into modularization. to process the additional function code. (such as logs, transactions, and security verification) We understand the role of this module as a aspect and tell us that it is a functional module. we can regard it as a plane. to put it bluntly, we write a class, in which we write some methods that process the same effect as the core business. so everyone should understand. the concept of professionalism is so hard to understand.

Second, the connection point (joinpoint). A simple understanding is the method defined in the Section module, that is, the method defined in the class above.

Third, pointcut is the set of connection points, which is the set of methods.

Fourth: Notification (advice). A simple understanding is to tell a method when to trigger execution. It is regarded as a condition judgment to determine when this method will be executed.

The following are some of my understandings. The target object is the core business to be processed. The proxy is easier to understand and allows a proxy to complete this task.

This is written briefly today and later.

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.